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

Wallet and Backup Payment #604

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Tests/Recurly/Billing_Info_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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);

Expand Down
79 changes: 79 additions & 0 deletions Tests/fixtures/billing_info/show-200-wallet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<billing_infos type="array">
<billing_info href="https://api.recurly.com/v2/accounts/abcdef1234567890/billing_infos/iiznlrvdt05b" type="credit_card">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<uuid>iiznlrvdt05b</uuid>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<company nil="nil"/>
<address1>123 Main St.</address1>
<address2 nil="nil"/>
<city>San Francisco</city>
<state>CA</state>
<zip>94105</zip>
<country>US</country>
<phone nil="nil"/>
<vat_number nil="nil"/>
<ip_address>127.0.0.1</ip_address>
<ip_address_country nil="nil"/>
<card_type>Visa</card_type>
<year type="integer">2019</year>
<month type="integer">11</month>
<first_six>411111</first_six>
<last_four>1111</last_four>
<primary_payment_method>true</primary_payment_method>
<backup_payment_method>false</backup_payment_method>
<updated_at type="datetime">2017-02-17T15:38:53Z</updated_at>
</billing_info>
<billing_info href="https://api.recurly.com/v2/accounts/abcdef1234567890/billing_infos/iiznlrvdt8py" type="credit_card">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<uuid>iiznlrvdt8py</uuid>
<first_name>Venice</first_name>
<last_name>Example</last_name>
<company nil="nil"/>
<address1>123 Main St.</address1>
<address2 nil="nil"/>
<city>San Francisco</city>
<state>CA</state>
<zip>94105</zip>
<country>US</country>
<phone nil="nil"/>
<vat_number nil="nil"/>
<ip_address>127.0.0.1</ip_address>
<ip_address_country nil="nil"/>
<card_type>Visa</card_type>
<year type="integer">2019</year>
<month type="integer">11</month>
<first_six>400011</first_six>
<last_four>1111</last_four>
<primary_payment_method>false</primary_payment_method>
<backup_payment_method>true</backup_payment_method>
<updated_at type="datetime">2017-02-17T15:38:53Z</updated_at>
</billing_info>
<billing_info href="https://api.recurly.com/v2/accounts/abcdef1234567890/billing_infos/2438622711411438053" type="bank_account">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<name_on_account>Acme, Inc.</name_on_account>
<first_name nil="nil"></first_name>
<last_name nil="nil"></last_name>
<company nil="nil"></company>
<address1>123 Main St.</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94105</zip>
<country>US</country>
<phone></phone>
<vat_number></vat_number>
<ip_address>127.0.0.1</ip_address>
<ip_address_country>US</ip_address_country>
<account_type>checking</account_type>
<last_four>5555</last_four>
<routing_number>065400137</routing_number>
<primary_payment_method>false</primary_payment_method>
<backup_payment_method>false</backup_payment_method>
<updated_at type="datetime">2017-02-17T15:38:53Z</updated_at>
</billing_info>
</billing_infos>
4 changes: 3 additions & 1 deletion Tests/fixtures/billing_info/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Content-Type: application/xml; charset=utf-8
<ip_address>127.0.0.1</ip_address>
<ip_address_country nil="nil"></ip_address_country>
<card_type>Visa</card_type>
<year type="integer">2015</year>
<year type="integer">2049</year>
<month type="integer">1</month>
<first_six>411111</first_six>
<last_four>1111</last_four>
<primary_payment_method type="boolean">true</primary_payment_method>
<backup_payment_method type="boolean">false</backup_payment_method>
<updated_at type="datetime">2017-02-17T15:38:53Z</updated_at>
</billing_info>
30 changes: 30 additions & 0 deletions lib/recurly/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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';
}
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion lib/recurly/billing_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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'
);
}
}
23 changes: 23 additions & 0 deletions lib/recurly/billing_info_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Recurly_BillingInfoList extends Recurly_Pager
{
public static function get($accountCode, $params = null, $client = null) {
$uri = self::_uriWithParams(self::_safeUri(Recurly_Client::PATH_ACCOUNTS, $accountCode, 'billing_infos'), $params);
return new self($uri, $client);
}

/**
* Performs a request with the `per_page` set to `n` and only returns
* the first `n` results in the response.
*/
public static function take($n, $accountCode, $params = null, $client = null) {
$params['per_page'] = $n;
$pager = self::get($accountCode, $params, $client);
return $pager->get_first_page();
}

protected function getNodeName() {
return 'billing_infos';
}
}
1 change: 1 addition & 0 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
);
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function getNodeName() {
}
protected function getWriteableAttributes() {
return array(
'account', 'adjustments', 'collection_method', 'currency', 'po_number',
'account', 'adjustments', 'billing_info_uuid', 'collection_method', 'currency', 'po_number',
chrissrogers marked this conversation as resolved.
Show resolved Hide resolved
'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'
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down