From 042d84645cd0216395de43c9e7348399e46c49c4 Mon Sep 17 00:00:00 2001 From: Joanna Sese Date: Mon, 12 Apr 2021 10:29:37 -0500 Subject: [PATCH 1/2] Implement wallet --- Tests/Recurly/Billing_Info_Test.php | 10 ++- .../fixtures/billing_info/show-200-wallet.xml | 79 +++++++++++++++++++ Tests/fixtures/billing_info/show-200.xml | 4 +- lib/recurly/account.php | 30 +++++++ lib/recurly/base.php | 1 + lib/recurly/billing_info.php | 5 +- lib/recurly/billing_info_list.php | 23 ++++++ lib/recurly/client.php | 1 + lib/recurly/invoice.php | 3 +- lib/recurly/purchase.php | 3 +- lib/recurly/subscription.php | 3 +- 11 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 Tests/fixtures/billing_info/show-200-wallet.xml create mode 100644 lib/recurly/billing_info_list.php diff --git a/Tests/Recurly/Billing_Info_Test.php b/Tests/Recurly/Billing_Info_Test.php index e87e83ef..34948dc9 100644 --- a/Tests/Recurly/Billing_Info_Test.php +++ b/Tests/Recurly/Billing_Info_Test.php @@ -6,6 +6,7 @@ class Recurly_BillingInfoTest extends Recurly_TestCase function defaultResponses() { return array( array('GET', '/accounts/abcdef1234567890/billing_info', 'billing_info/show-200.xml'), + array('GET', '/accounts/abcdef1234567890z/billing_infos', 'billing_info/show-200-wallet.xml'), array('GET', '/accounts/paypal1234567890/billing_info', 'billing_info/show-paypal-200.xml'), array('GET', '/accounts/amazon1234567890/billing_info', 'billing_info/show-amazon-200.xml'), array('GET', '/accounts/bankaccount1234567890/billing_info', 'billing_info/show-bank-account-200.xml'), @@ -27,12 +28,19 @@ public function testGetBillingInfo() { $this->assertEquals($billing_info->address1, '123 Pretty Pretty Good St.'); $this->assertEquals($billing_info->country, 'US'); $this->assertEquals($billing_info->card_type, 'Visa'); - $this->assertEquals($billing_info->year, 2015); + $this->assertEquals($billing_info->year, 2049); $this->assertEquals($billing_info->month, 1); + $this->assertTrue($billing_info->primary_payment_method); + $this->assertFalse($billing_info->backup_payment_method); $this->assertEquals($billing_info->getHref(), 'https://api.recurly.com/v2/accounts/abcdef1234567890/billing_info'); $this->assertEquals($billing_info->getType(), 'credit_card'); } + public function testGetBillingInfos() { + $billing_infos = Recurly_BillingInfoList::get('abcdef1234567890', $this->client); + $this->assertInstanceOf('Recurly_BillingInfoList', $billing_infos); + } + public function testGetPayPalBillingInfo() { $billing_info = Recurly_BillingInfo::get('paypal1234567890', $this->client); diff --git a/Tests/fixtures/billing_info/show-200-wallet.xml b/Tests/fixtures/billing_info/show-200-wallet.xml new file mode 100644 index 00000000..f6e4fd0f --- /dev/null +++ b/Tests/fixtures/billing_info/show-200-wallet.xml @@ -0,0 +1,79 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + iiznlrvdt05b + Verena + Example + + 123 Main St. + + San Francisco + CA + 94105 + US + + + 127.0.0.1 + + Visa + 2019 + 11 + 411111 + 1111 + true + false + 2017-02-17T15:38:53Z + + + + iiznlrvdt8py + Venice + Example + + 123 Main St. + + San Francisco + CA + 94105 + US + + + 127.0.0.1 + + Visa + 2019 + 11 + 400011 + 1111 + false + true + 2017-02-17T15:38:53Z + + + + Acme, Inc. + + + + 123 Main St. + + San Francisco + CA + 94105 + US + + + 127.0.0.1 + US + checking + 5555 + 065400137 + false + false + 2017-02-17T15:38:53Z + + diff --git a/Tests/fixtures/billing_info/show-200.xml b/Tests/fixtures/billing_info/show-200.xml index 93b7aa68..4c217411 100644 --- a/Tests/fixtures/billing_info/show-200.xml +++ b/Tests/fixtures/billing_info/show-200.xml @@ -18,9 +18,11 @@ Content-Type: application/xml; charset=utf-8 127.0.0.1 Visa - 2015 + 2049 1 411111 1111 + true + false 2017-02-17T15:38:53Z diff --git a/lib/recurly/account.php b/lib/recurly/account.php index d9d5e1dd..2a6c1933 100644 --- a/lib/recurly/account.php +++ b/lib/recurly/account.php @@ -92,6 +92,32 @@ public function createShippingAddress($shippingAddress, $client = null) { $shippingAddress->_save(Recurly_Client::POST, $this->uri() . '/shipping_addresses'); } + public function createBillingInfo($billingInfo, $client = null) { + if ($client) { + $billingInfo -> _client = $client; + } + $billingInfo -> _save(Recurly_Client::POST, $this->uri() . '/billing_infos'); + } + + public function updateBillingInfo($billingInfo, $client = null) { + if ($client) { + $billingInfo -> _client = $client; + } + $billingInfo -> _save(Recurly_Client::PUT, $this->uri() . '/billing_infos/' . $billingInfo->uuid); + } + + public function getBillingInfos($client = null) { + return Recurly_Base::_get($this->uriForBillingInfos(), $client); + } + + public function getBillingInfo($billingInfoUuid, $client = null) { + return Recurly_Base::_get($this->uriForBillingInfos() . '/' . $billingInfoUuid, $client); + } + + public function deleteBillingInfo($billingInfoUuid, $client = null) { + return Recurly_Base::_delete($this->uriForBillingInfos() . '/' . $billingInfoUuid, $client); + } + protected function uri() { if (!empty($this->_href)) return $this->getHref(); @@ -102,6 +128,10 @@ protected static function uriForAccount($accountCode) { return self::_safeUri(Recurly_Client::PATH_ACCOUNTS, $accountCode); } + protected function uriForBillingInfos() { + return Recurly_Account::uriForAccount($this->account_code) . '/' . Recurly_Client::PATH_BILLING_INFOS; + } + protected function getNodeName() { return 'account'; } diff --git a/lib/recurly/base.php b/lib/recurly/base.php index 938a9843..38c27c78 100644 --- a/lib/recurly/base.php +++ b/lib/recurly/base.php @@ -245,6 +245,7 @@ public function getLinks() { 'adjustments' => 'Recurly_AdjustmentList', 'balance_in_cents' => 'Recurly_CurrencyList', 'billing_info' => 'Recurly_BillingInfo', + 'billing_infos' => 'Recurly_BillingInfoList', 'coupon' => 'Recurly_Coupon', 'unique_coupon_codes' => 'Recurly_UniqueCouponCodeList', 'charge_invoice' => 'Recurly_Invoice', diff --git a/lib/recurly/billing_info.php b/lib/recurly/billing_info.php index cd2ff300..317f3720 100644 --- a/lib/recurly/billing_info.php +++ b/lib/recurly/billing_info.php @@ -3,6 +3,7 @@ /** * class Recurly_BillingInfo * @property string $account_code Account's unique code. + * @property string $uuid Billing info uuid * @property-write string $token_id A token generated by Recurly.js * @property string $currency Currency in which invoices will be posted. Only applicable if this account is enrolled in a plan has a different currency than your site's default. * @property string $first_name First name @@ -45,6 +46,8 @@ * @property string $bsb_code Bank identifier code for AU based banks. Required for Becs based billing infos. * @property string $tax_identifier Tax identifier is required if adding a billing info that is a consumer card in Brazil. This would be the customer's CPF, a Brazilian tax identifier for all tax paying residents. * @property string $tax_identifier_type This field and a value of 'cpf' are required if adding a billing info that is an elo or hipercard type in Brazil. + * @property boolean $primary_payment_method Primary payment method + * @property boolean $backup_payment_method Backup payment method */ class Recurly_BillingInfo extends Recurly_Resource { @@ -129,7 +132,7 @@ protected function getWriteableAttributes() { 'token_id', 'external_hpp_type', 'gateway_token', 'gateway_code', 'braintree_payment_nonce', 'roku_billing_agreement_id', 'three_d_secure_action_result_token_id', 'transaction_type', 'iban', 'sort_code', 'bsb_code', 'type', - 'tax_identifier', 'tax_identifier_type' + 'tax_identifier', 'tax_identifier_type', 'primary_payment_method', 'backup_payment_method' ); } } diff --git a/lib/recurly/billing_info_list.php b/lib/recurly/billing_info_list.php new file mode 100644 index 00000000..8b8a2d93 --- /dev/null +++ b/lib/recurly/billing_info_list.php @@ -0,0 +1,23 @@ +get_first_page(); + } + + protected function getNodeName() { + return 'billing_infos'; + } +} diff --git a/lib/recurly/client.php b/lib/recurly/client.php index c04ba917..8f474da0 100644 --- a/lib/recurly/client.php +++ b/lib/recurly/client.php @@ -65,6 +65,7 @@ class Recurly_Client const PATH_ADJUSTMENTS = 'adjustments'; const PATH_BALANCE = 'balance'; const PATH_BILLING_INFO = 'billing_info'; + const PATH_BILLING_INFOS = 'billing_infos'; const PATH_COUPON = 'coupon'; const PATH_COUPON_REDEMPTION = 'redemption'; const PATH_COUPON_REDEMPTIONS = 'redemptions'; diff --git a/lib/recurly/invoice.php b/lib/recurly/invoice.php index 89134583..12d6d7c9 100644 --- a/lib/recurly/invoice.php +++ b/lib/recurly/invoice.php @@ -7,6 +7,7 @@ * @property Recurly_ShippingAddress $shipping_address * @property Recurly_BillingInfo $billing_info * @property string $uuid + * @property string $billing_info_uuid The uuid to indicate which billing info to use from wallet. * @property string $state * @property int $invoice_number_prefix * @property int $invoice_number @@ -234,7 +235,7 @@ protected function getNodeName() { } protected function getWriteableAttributes() { return array( - 'address', 'billing_info', 'terms_and_conditions', 'customer_notes', 'vat_reverse_charge_notes', + 'address', 'billing_info', 'billing_info_uuid', 'terms_and_conditions', 'customer_notes', 'vat_reverse_charge_notes', 'collection_method', 'net_terms', 'po_number', 'currency', 'credit_customer_notes', 'gateway_code' ); diff --git a/lib/recurly/purchase.php b/lib/recurly/purchase.php index 702ea985..b05de2af 100644 --- a/lib/recurly/purchase.php +++ b/lib/recurly/purchase.php @@ -4,6 +4,7 @@ * @property Recurly_Account $account The account for the purchase. Can create an account or use existing. * @property Recurly_Adjustment[] $adjustments The array of adjustments for the purchase. * @property string $collection_method The invoice collection method ('automatic' or 'manual'). + * @property string $billing_info_uuid The uuid to indicate which billing info to use from wallet. * @property string $currency The currency to use in this invoice. * @property string $po_number The po number for the invoice. * @property integer $net_terms The net terms of the invoice. @@ -115,7 +116,7 @@ protected function getNodeName() { } protected function getWriteableAttributes() { return array( - 'account', 'adjustments', 'collection_method', 'currency', 'po_number', + 'account', 'adjustments', 'collection_method', 'billing_info_uuid', 'currency', 'po_number', 'net_terms', 'subscriptions', 'gift_card', 'coupon_codes', 'customer_notes', 'terms_and_conditions', 'vat_reverse_charge_notes', 'shipping_address', 'shipping_address_id', 'gateway_code', 'shipping_fees', 'transaction_type' diff --git a/lib/recurly/subscription.php b/lib/recurly/subscription.php index eca178a5..85e926c0 100644 --- a/lib/recurly/subscription.php +++ b/lib/recurly/subscription.php @@ -7,6 +7,7 @@ * @property string $plan_code plan_code for the subscription. * @property-read Recurly_Plan $plan Nested plan_code and plan name * @property Recurly_Stub $account Nested account attributes. + * @property string $billing_info_uuid The uuid to indicate which billing info to use from wallet. * @property string $currency Currency for the subscription. * @property mixed[] $subscription_add_ons Nested add-ons. * @property string $coupon_code Optional coupon code to redeem on the account and discount the subscription. Please note, the subscription request will fail if the coupon is invalid. @@ -312,7 +313,7 @@ protected function getNodeName() { protected function getWriteableAttributes() { return array( 'account', 'billing_info', 'plan_code', 'coupon_code', 'coupon_codes', - 'unit_amount_in_cents', 'quantity', 'currency', 'starts_at', + 'unit_amount_in_cents', 'quantity', 'billing_info_uuid', 'currency', 'starts_at', 'trial_ends_at', 'total_billing_cycles', 'first_renewal_date', 'timeframe', 'subscription_add_ons', 'net_terms', 'po_number', 'collection_method', 'cost_in_cents', 'remaining_billing_cycles', 'bulk', From 8df9c5d124d77a10b3b3d561fc0bcb451607f05a Mon Sep 17 00:00:00 2001 From: Joanna Sese Date: Fri, 16 Apr 2021 14:50:20 -0500 Subject: [PATCH 2/2] Alphabetize writeable attrs --- lib/recurly/purchase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recurly/purchase.php b/lib/recurly/purchase.php index b05de2af..e47a5780 100644 --- a/lib/recurly/purchase.php +++ b/lib/recurly/purchase.php @@ -116,7 +116,7 @@ protected function getNodeName() { } protected function getWriteableAttributes() { return array( - 'account', 'adjustments', 'collection_method', 'billing_info_uuid', 'currency', 'po_number', + 'account', 'adjustments', 'billing_info_uuid', 'collection_method', 'currency', 'po_number', 'net_terms', 'subscriptions', 'gift_card', 'coupon_codes', 'customer_notes', 'terms_and_conditions', 'vat_reverse_charge_notes', 'shipping_address', 'shipping_address_id', 'gateway_code', 'shipping_fees', 'transaction_type'