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

Add 'Delete' to ShippingAddress object #457

Merged
merged 1 commit into from
Jan 21, 2020
Merged

Conversation

joannasese
Copy link
Contributor

@joannasese joannasese commented Jan 14, 2020

  • Add delete function to ShippingAddress object
  • Add unit test

To delete a shipping address by id (id = 2922857578120715120 in this example):

$shipping_addresses = Recurly_ShippingAddressList::get($account->account_code);

foreach ($shipping_addresses as $address) {
    if ($address->id == 2922857578120715120){
      $address->delete();
    }
}

To delete all shipping addresses associated with account:

$shipping_addresses = Recurly_ShippingAddressList::get($account->account_code);

foreach ($shipping_addresses as $address) {
    $address->delete();
} 

@joannasese joannasese marked this pull request as ready for review January 14, 2020 19:45
@joannasese joannasese changed the title Delete Shipping Address Add 'Delete' to ShippingAddress object Jan 14, 2020
@joannasese joannasese requested a review from bhelx January 14, 2020 20:09

$shipping_addresses = Recurly_ShippingAddressList::get('abcdef1234567890', null, $this->client);

foreach ($shipping_addresses as $shipping_address) {
Copy link
Contributor

@bhelx bhelx Jan 14, 2020

Choose a reason for hiding this comment

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

I think it's safe to just take the first one?

$shipping_addresses[0]->delete();

If you want to make it more future proof (optional). You can use the shipping address to setup the stub. Something like:

$address = $shipping_addresses[0];
$this->client->addResponse('DELETE', 'https://api.recurly.com/v2/accounts/abcdef1234567890/shipping_addresses/' . $address->id, 'shipping_addresses/destroy-204.xml');

Copy link
Contributor Author

@joannasese joannasese Jan 16, 2020

Choose a reason for hiding this comment

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

shipping_addresses[0] yields Cannot use object of type Recurly_ShippingAddressList as array, which may or may have not led to a StackOverflow wormhole. It might explain why there are other instances of foreach being used.

@joannasese joannasese changed the title Add 'Delete' to ShippingAddress object [WAdd 'Delete' to ShippingAddress object Jan 16, 2020
@joannasese joannasese changed the title [WAdd 'Delete' to ShippingAddress object [WIP] Add 'Delete' to ShippingAddress object Jan 16, 2020
@joannasese joannasese changed the title [WIP] Add 'Delete' to ShippingAddress object Add 'Delete' to ShippingAddress object Jan 16, 2020
Copy link
Contributor

@bhelx bhelx left a comment

Choose a reason for hiding this comment

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

👍

@bhelx bhelx merged commit 224209d into master Jan 21, 2020
@bhelx bhelx deleted the dx-62-delete-shipping-address branch January 21, 2020 22:49
@joannasese joannasese mentioned this pull request Feb 20, 2020
@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