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

Moto transactions #420

Merged
merged 2 commits into from
Aug 21, 2019
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
12 changes: 12 additions & 0 deletions Tests/Recurly/Account_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public function testXml() {
);
}

/**
* Test that transaction_type is rendered
*/
public function testTransactionType() {
$account = Recurly_Account::get('abcdef1234567890', $this->client);
$account->transaction_type = 'moto';
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><transaction_type>moto</transaction_type></account>\n",
$account->xml()
);
}

/**
* Test that updates to nested account addresses are detected when generating
* XML to send.
Expand Down
11 changes: 11 additions & 0 deletions Tests/Recurly/Billing_Info_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public function testCreateForAccountWithToken() {
$billing_info->create();
}

public function testTransactionType() {
$billing_info = new Recurly_BillingInfo(null, $this->client);
$billing_info->transaction_type = 'moto';

$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><transaction_type>moto</transaction_type></billing_info>\n"
);
}

public function testForExternalHppType() {
$billing_info = new Recurly_BillingInfo(null, $this->client);
$billing_info->token_id = 'abc123';
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testForceCollect() {
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/invoices/1001/collect', 'invoices/force_collect-200.xml');

$invoice = Recurly_Invoice::get('1001', $this->client);
$invoice->forceCollect();
$invoice->forceCollect('moto');
$this->assertEquals($invoice->state, 'paid');
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function defaultResponses() {

public function mockPurchase() {
$purchase = new Recurly_Purchase();
$purchase->transaction_type = 'moto';
$purchase->currency = 'USD';
$purchase->gateway_code = 'aBcD1234';
$purchase->collection_method = 'automatic';
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testXml() {
$purchase = $this->mockPurchase();

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<purchase><account><account_code>aba9209a-aa61-4790-8e61-0a2692435fee</account_code><billing_info><token_id>7z6furn4jvb9</token_id></billing_info><address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone></address><shipping_addresses><shipping_address><address1>400 Dolores St</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><nickname>Home</nickname><first_name>Dolores</first_name><last_name>Du Monde</last_name></shipping_address></shipping_addresses></account><adjustments><adjustment><currency>USD</currency><unit_amount_in_cents>1000</unit_amount_in_cents><quantity>1</quantity><revenue_schedule_type>at_invoice</revenue_schedule_type><product_code>abcd123</product_code></adjustment></adjustments><collection_method>automatic</collection_method><currency>USD</currency><customer_notes>Customer Notes</customer_notes><terms_and_conditions>Terms and Conditions</terms_and_conditions><vat_reverse_charge_notes>VAT Reverse Charge Notes</vat_reverse_charge_notes><gateway_code>aBcD1234</gateway_code></purchase>\n",
"<?xml version=\"1.0\"?>\n<purchase><account><account_code>aba9209a-aa61-4790-8e61-0a2692435fee</account_code><billing_info><token_id>7z6furn4jvb9</token_id></billing_info><address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone></address><shipping_addresses><shipping_address><address1>400 Dolores St</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><nickname>Home</nickname><first_name>Dolores</first_name><last_name>Du Monde</last_name></shipping_address></shipping_addresses></account><adjustments><adjustment><currency>USD</currency><unit_amount_in_cents>1000</unit_amount_in_cents><quantity>1</quantity><revenue_schedule_type>at_invoice</revenue_schedule_type><product_code>abcd123</product_code></adjustment></adjustments><collection_method>automatic</collection_method><currency>USD</currency><customer_notes>Customer Notes</customer_notes><terms_and_conditions>Terms and Conditions</terms_and_conditions><vat_reverse_charge_notes>VAT Reverse Charge Notes</vat_reverse_charge_notes><gateway_code>aBcD1234</gateway_code><transaction_type>moto</transaction_type></purchase>\n",
$purchase->xml()
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @property DateTime $updated_at The date and time the account or its billing info was last updated.
* @property DateTime $closed_at For closed accounts, the date and time it was closed.
* @property Recurly_AccountAcquisition $account_acquisition The nested account acquisition information: cost_in_cents, currency, channel, subchannel, campaign.
* @property string $transaction_type Indicates type of resulting transaction. accepted_values: "moto".
*/
class Recurly_Account extends Recurly_Resource
{
Expand Down Expand Up @@ -109,7 +110,7 @@ protected function getWriteableAttributes() {
'email', 'company_name', 'accept_language', 'billing_info', 'address',
'tax_exempt', 'entity_use_code', 'cc_emails', 'shipping_addresses',
'preferred_locale', 'custom_fields', 'account_acquisition', 'exemption_certificate',
'parent_account_code'
'parent_account_code', 'transaction_type'
);
}
protected function getRequiredAttributes() {
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/billing_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @property string $amazon_billing_agreement_id Amazon's billing agreement
* @property string $braintree_payment_nonce Braintree's payment method nonce representing the Paypal billing agreement id. This is required when processing Paypal transactions through Braintree.
* @property string $roku_billing_agreement_id Roku's CIB if billing through Roku
* @property string $transaction_type Indicates type of resulting transaction. accepted_values: "moto".
*/
class Recurly_BillingInfo extends Recurly_Resource
{
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function getWriteableAttributes() {
'paypal_billing_agreement_id', 'amazon_billing_agreement_id', 'currency',
'token_id', 'external_hpp_type', 'gateway_token', 'gateway_code',
'braintree_payment_nonce', 'roku_billing_agreement_id',
'three_d_secure_action_result_token_id'
'three_d_secure_action_result_token_id', 'transaction_type'
);
}
}
2 changes: 1 addition & 1 deletion lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Recurly_Client
/**
* API Version
*/
public static $apiVersion = '2.21';
public static $apiVersion = '2.22';

/**
* The path to your CA certs. Use only if needed (if you can't fix libcurl/php).
Expand Down
11 changes: 9 additions & 2 deletions lib/recurly/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ public function markSuccessful() {
/**
* @throws Recurly_Error
*/
public function forceCollect() {
$this->_save(Recurly_Client::PUT, $this->uri() . '/collect');
public function forceCollect($transaction_type = null) {
$body = null;
if ($transaction_type != null) {
$doc = $this->createDocument();
$root = $doc->appendChild($doc->createElement('invoice'));
$root->appendChild($doc->createElement('transaction_type', $transaction_type));
$body = $this->renderXML($doc);
}
$this->_save(Recurly_Client::PUT, $this->uri() . '/collect', $body, $this->_client);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @property integer $shipping_address_id Optional id of an existing ShippingAddress to be applied to all subscriptions and adjustments in purchase.
* @property string $gateway_code Optional base36 encoded id for the gateway you wish to use for this transaction.
* @property Recurly_ShippingFee[] $shipping_fees Optional array of shipping fees to apply to the purchase.
* @property string $transaction_type Indicates type of resulting transaction. accepted_values: "moto".
*/
class Recurly_Purchase extends Recurly_Resource
{
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function getWriteableAttributes() {
'account', 'adjustments', 'collection_method', 'currency', 'po_number',
'net_terms', 'subscriptions', 'gift_card', 'coupon_codes', 'customer_notes',
'terms_and_conditions', 'vat_reverse_charge_notes', 'shipping_address_id',
'gateway_code', 'shipping_fees'
'gateway_code', 'shipping_fees', 'transaction_type'
);
}
}
3 changes: 2 additions & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @property string $gateway_code The unique identifier of a payment gateway used to specify which payment gateway you wish to process this subscriptions’ payments
* @property string $shipping_method_code The unique identifier of the shipping method for this subscription.
* @property integer $shipping_amount_in_cents The amount charged for shipping in cents.
* @property string $transaction_type Indicates type of resulting transaction. accepted_values: "moto".
*/
class Recurly_Subscription extends Recurly_Resource
{
Expand Down Expand Up @@ -279,7 +280,7 @@ protected function getWriteableAttributes() {
'shipping_address', 'shipping_address_id', 'imported_trial',
'remaining_pause_cycles', 'custom_fields', 'auto_renew',
'renewal_billing_cycles', 'gateway_code', 'shipping_method_code',
'shipping_amount_in_cents'
'shipping_amount_in_cents', 'transaction_type'
);
}
}