Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create shipping addresses on existing accounts and allow updates #289

Merged
merged 2 commits into from
Jan 9, 2017

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Dec 15, 2016

It seems we weren't able to create shipping addresses on existing accounts before. This method allows that. Also added the update() method.

Create on existing account

// work shipping address
$shad1 = new Recurly_ShippingAddress();
$shad1->nickname = "Work";
$shad1->first_name = "Verena";
$shad1->last_name = "Example";
$shad1->company = "Recurly Inc.";
$shad1->phone = "555-555-5555";
$shad1->email = "verena@example.com";
$shad1->address1 = "123 Main St.";
$shad1->city = "San Francisco";
$shad1->state = "CA";
$shad1->zip = "94110";
$shad1->country = "US";

// home shipping address
$shad2 = new Recurly_ShippingAddress();
$shad2->nickname = "Home";
$shad2->first_name = "Verena";
$shad2->last_name = "Example";
$shad2->phone = "555-555-5555";
$shad2->email = "verena@example.com";
$shad2->address1 = "123 Dolores St.";
$shad2->city = "San Francisco";
$shad2->state = "CA";
$shad2->zip = "94110";
$shad2->country = "US";

// some random billing info for the account
$billing_info = new Recurly_BillingInfo();
$billing_info->first_name = 'Verena';
$billing_info->last_name = 'Example';
$billing_info->number = '4111-1111-1111-1111';
$billing_info->month = 12;
$billing_info->year = 2019;
$billing_info->verification_value = '123';
$billing_info->address1 = '400 Alabama St';
$billing_info->city = 'San Francisco';
$billing_info->state = 'CA';
$billing_info->country = 'US';
$billing_info->zip = '94110';

$account_code = uniqid();
$account = new Recurly_Account();
$account->account_code = $account_code;
$account->billing_info = $billing_info;

// set one of them on create
$account->shipping_addresses = array($shad1);

// create the account
$account->create();

// create the other shipping address on this existing account
$account->createShippingAddress($shad2);

// we should have 2 now
print var_dump($account->shipping_addresses->get());

// check the dashboard as well
print $account->account_code;

Update a shipping address

// given an account with shipping address on it
$shipping_addresses = $account->shipping_addresses->get();

$nick = 'Work';
$newAddress = '210 Beach Street';
foreach ($shipping_addresses as $shipping_address)  {
  if ($shipping_address->nickname == $nick)  {
    $shipping_address->address1 = $newAddress;
    $shipping_address->update();
    print $shipping_address->address1;
  }
}

@bhelx bhelx added the WIP label Dec 15, 2016
@bhelx bhelx requested a review from drewish December 15, 2016 21:30
@bhelx bhelx changed the title [WIP] Create shipping addresses on existing accounts [WIP] Create shipping addresses on existing accounts and allow updates Dec 15, 2016
@bhelx bhelx changed the title [WIP] Create shipping addresses on existing accounts and allow updates Create shipping addresses on existing accounts and allow updates Jan 6, 2017
@bhelx bhelx removed the WIP label Jan 6, 2017

foreach ($shipping_addresses as $shipping_address) {
if ($shipping_address->nickname == 'Home') {
$shipping_address->_client = $this->client; // for tests
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this get passed down automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing a problem before but removing it now works :)

@bhelx bhelx force-pushed the create_shipping_address_on_existing_account branch from 0751030 to f59bfa7 Compare January 9, 2017 17:31
@drewish drewish merged commit 706163b into master Jan 9, 2017
@drewish drewish deleted the create_shipping_address_on_existing_account branch January 9, 2017 17:45
@bhelx bhelx mentioned this pull request Jan 9, 2017
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants