nish
nish

Reputation: 256

Cannot add address info in Create Account API in PHP

I tried creating an account as the below code snippet (using http://docs.recurly.com/api/accounts#create-account) , the account is created but can't include the address info in account.

$account = new Recurly_Account('1'); 
$account->email = $_POST['emailaddress']; 
$account->first_name = $_POST['firstname']; 
$account->last_name = $_POST['lastname']; 

$address = new Recurly_Address(); 
$address->address1 = $_POST['address']; 
$address->country = $_POST['country']; 
$address->city = $_POST['city']; 
$address->phone = $_POST['phone']; 
$address->state = $_POST['state']; 
$address->zip = $_POST['zipcode'];


$account->address = $address; 

$check = $account->create();

Upvotes: 1

Views: 252

Answers (3)

Charlie Gerrior Jr.
Charlie Gerrior Jr.

Reputation: 86

Your syntax and everything else looks OK. I was able to use your code (modified slightly):

$account = new Recurly_Account('1'); 
$account->email = '[email protected]'; 
$account->first_name = 'firstname'; 
$account->last_name = 'lastname'; 

$address = new Recurly_Address(); 
$address->address1 = 'address'; 
$address->country = 'country'; 
$address->city = 'city'; 
$address->phone = 'phone'; 
$address->state = 'state'; 
$address->zip = 'zipcode';


$account->address = $address; 

$account->create();

to create an account w/ address info. Maybe for each of the address fields $_POST['field'] evaluates to '' (empty string)? The only required field is the account code which you specify when you call Recurly_Account, so in this case the account would be created, but all of its parameters would be empty.

Upvotes: 1

Danzzz
Danzzz

Reputation: 535

You should set also "account_code" for the Address:

$address->account_code = '1';

Upvotes: 0

sreekanth balu
sreekanth balu

Reputation: 178

have you tried post array as it says nested values in address.

$_POST['address'] = array( 'country', 'city' );

Upvotes: 0

Related Questions