Skip to content

Commit

Permalink
Merge pull request #780 from recurly/add-action-result-field
Browse files Browse the repository at this point in the history
[V2] Add action_result to Subscription and Transaction
  • Loading branch information
douglaslise authored Aug 8, 2023
2 parents 3bbab02 + 4daf544 commit f196298
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Recurly_PurchaseTest extends Recurly_TestCase
function defaultResponses() {
return array(
array('POST', '/purchases', 'purchases/create-201.xml'),
array('POST', '/purchases', 'purchases/create-with-action-result-201.xml'),
array('POST', '/purchases/preview', 'purchases/preview-200.xml'),
array('POST', '/purchases/authorize', 'purchases/authorize-200.xml'),
array('POST', '/purchases/pending', 'purchases/pending-200.xml'),
Expand Down Expand Up @@ -165,4 +166,12 @@ public function testTransactionError() {
$this->fail('Purchase should have thrown transaction exception');
}
}

public function testPurchaseIncludesTransactionActionResultResponse(){
$this->client->addResponse('POST', '/purchases', 'purchases/create-with-action-result-201.xml');

$purchase = new Recurly_Purchase(null, $this->client);
$collection = Recurly_Purchase::invoice($purchase, $this->client);
$this->assertEquals('example', $collection->charge_invoice->transactions->current()->action_result);
}
}
13 changes: 13 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,17 @@ public function testConvertTrialWithout3DSToken() {
$subscription->convertTrial();
$this->assertEquals($subscription->trial_ends_at, $subscription->current_period_started_at);
}

public function testPreviewNewSubscriptionWithActionResult(){

$this->client->addResponse('POST', '/subscriptions/preview', 'subscriptions/preview-200-new-with-action-result.xml');
$subscription = new Recurly_Subscription(null, $this->client);

$subscription->account = new Recurly_Account();
$subscription->account->account_code = '1';
$subscription->account->billing_info = new Recurly_BillingInfo();
$subscription->account->billing_info->token_id = 'abc123';
$subscription->preview();
$this->assertEquals('example', $subscription->action_result);
}
}
8 changes: 8 additions & 0 deletions Tests/Recurly/Transaction_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,12 @@ public function testGetFailedTransaction() {
$this->assertEquals('Your card number is not valid. Please update your card number.', $transaction->transaction_error->customer_message);
$this->assertEquals('123', $transaction->transaction_error->gateway_error_code);
}

public function testTransactionWithActionResultResponse(){
$this->client->addResponse('POST', '/transactions', 'transactions/create-with-action-result-200.xml');

$transaction = new Recurly_Transaction(null, $this->client);
$transaction->create();
$this->assertEquals('example', $transaction->action_result);
}
}
144 changes: 144 additions & 0 deletions Tests/fixtures/purchases/create-with-action-result-201.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/invoices/3704

<?xml version="1.0" encoding="UTF-8"?>
<invoice_collection>
<charge_invoice href="https://api.recurly.com/v2/invoices/3704">
<account href="https://api.recurly.com/v2/accounts/6b97ec05-7e9d-4506-a4b6-5459acbd6403"/>
<address>
<address1>400 Alabama St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone nil="nil"></phone>
</address>
<uuid>3d8648fcf2be67ed304ff242d6bbb9d4</uuid>
<state>paid</state>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number type="integer">3704</invoice_number>
<po_number nil="nil"></po_number>
<vat_number nil="nil"></vat_number>
<subtotal_in_cents type="integer">1000</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1000</total_in_cents>
<subtotal_after_discount_in_cents type="integer">1000</subtotal_after_discount_in_cents>
<currency>USD</currency>
<created_at type="datetime">2017-05-17T17:38:55Z</created_at>
<updated_at type="datetime">2017-05-17T17:38:55Z</updated_at>
<attempt_next_collection_at nil="nil"></attempt_next_collection_at>
<closed_at type="datetime">2017-05-17T17:38:55Z</closed_at>
<terms_and_conditions nil="nil"></terms_and_conditions>
<customer_notes nil="nil"></customer_notes>
<recovery_reason nil="nil"></recovery_reason>
<net_terms type="integer">0</net_terms>
<collection_method>automatic</collection_method>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/3d8648fced80685b7f165a43fca65cda" type="charge">
<account href="https://api.recurly.com/v2/accounts/6b97ec05-7e9d-4506-a4b6-5459acbd6403"/>
<invoice href="https://api.recurly.com/v2/invoices/3704"/>
<uuid>3d8648fced80685b7f165a43fca65cda</uuid>
<state>invoiced</state>
<description nil="nil"></description>
<accounting_code nil="nil"></accounting_code>
<product_code>4549449c-5870-4845-b672-1d07f15e87dd</product_code>
<origin>debit</origin>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1000</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<tax_exempt type="boolean">false</tax_exempt>
<tax_code nil="nil"></tax_code>
<start_date type="datetime">2017-05-17T17:38:55Z</start_date>
<end_date nil="nil"></end_date>
<created_at type="datetime">2017-05-17T17:38:55Z</created_at>
<updated_at type="datetime">2017-05-17T17:38:55Z</updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<shipping_address>
<first_name>Dolores</first_name>
<last_name>Du Monde</last_name>
<address1>400 Dolores St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<nickname>Home</nickname>
</shipping_address>
<custom_fields type="array">
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
<transaction href="https://api.recurly.com/v2/transactions/3d8648fd0cc7c6e9196b944878afcd3d" type="credit_card">
<account href="https://api.recurly.com/v2/accounts/6b97ec05-7e9d-4506-a4b6-5459acbd6403"/>
<invoice href="https://api.recurly.com/v2/invoices/3704"/>
<uuid>3d8648fd0cc7c6e9196b944878afcd3d</uuid>
<action>purchase</action>
<amount_in_cents type="integer">1000</amount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<currency>USD</currency>
<status>success</status>
<payment_method>credit_card</payment_method>
<reference>135998</reference>
<source>transaction</source>
<recurring type="boolean">false</recurring>
<test type="boolean">true</test>
<voidable type="boolean">true</voidable>
<refundable type="boolean">true</refundable>
<ip_address nil="nil"></ip_address>
<gateway_type>test</gateway_type>
<origin>api</origin>
<description nil="nil"></description>
<message>Successful test transaction</message>
<approval_code nil="nil"></approval_code>
<failure_type nil="nil"></failure_type>
<gateway_error_codes nil="nil"></gateway_error_codes>
<cvv_result code="" nil="nil"></cvv_result>
<avs_result code="D">Street address and postal code match.</avs_result>
<avs_result_street nil="nil"></avs_result_street>
<avs_result_postal nil="nil"></avs_result_postal>
<created_at type="datetime">2017-05-17T17:38:55Z</created_at>
<collected_at type="datetime">2017-05-17T17:38:55Z</collected_at>
<updated_at type="datetime">2017-05-17T17:38:55Z</updated_at>
<details>
<account>
<account_code>6b97ec05-7e9d-4506-a4b6-5459acbd6403</account_code>
<first_name nil="nil"></first_name>
<last_name nil="nil"></last_name>
<company nil="nil"></company>
<email nil="nil"></email>
<billing_info type="credit_card">
<first_name>Benjamin</first_name>
<last_name>Du Monde</last_name>
<address1>400 Alabama St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone nil="nil"></phone>
<vat_number nil="nil"></vat_number>
<card_type>Visa</card_type>
<year type="integer">2019</year>
<month type="integer">12</month>
<first_six>411111</first_six>
<last_four>1111</last_four>
</billing_info>
</account>
</details>
<action-result>example</action-result>
</transaction>
</transactions>
<a name="refund" href="https://api.recurly.com/v2/invoices/3704/refund" method="post"/>
</charge_invoice>
</invoice_collection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<subscription href="">
<plan href="https://api.recurly.com/v2/plans/gold">
<plan_code>gold</plan_code>
<name>gold</name>
</plan>
<uuid>012345678901234567890123456789ab</uuid>
<state>pending</state>
<unit_amount_in_cents type="integer">10000</unit_amount_in_cents>
<currency>USD</currency>
<quantity type="integer">1</quantity>
<activated_at nil="nil"></activated_at>
<canceled_at nil="nil"></canceled_at>
<expires_at nil="nil"></expires_at>
<total_billing_cycles nil="nil"></total_billing_cycles>
<remaining_billing_cycles nil="nil"></remaining_billing_cycles>
<current_period_started_at type="datetime">2014-05-16T20:39:21Z</current_period_started_at>
<current_period_ends_at type="datetime">2014-05-16T20:39:21Z</current_period_ends_at>
<trial_started_at nil="nil"></trial_started_at>
<trial_ends_at nil="nil"></trial_ends_at>
<cost_in_cents type="integer">10000</cost_in_cents>
<subscription_add_ons type="array">
</subscription_add_ons>
<action_result>example</action_result>
</subscription>
46 changes: 46 additions & 0 deletions Tests/fixtures/transactions/create-with-action-result-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<transaction href="https://api.recurly.com/v2/transactions/abcdef1234567890">
<account href="https://api.recurly.com/v2/accounts/verena"/>
<invoice href="https://api.recurly.com/v2/invoices/abcdef1234567890"/>
<uuid>a13acd8fe4294916b79aec87b7ea441f</uuid>
<action>purchase</action>
<amount_in_cents type="integer">100</amount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<currency>USD</currency>
<status>success</status>
<payment_method>check</payment_method>
<reference nil="nil"></reference>
<source>transaction</source>
<recurring type="boolean">false</recurring>
<test type="boolean">true</test>
<voidable type="boolean">true</voidable>
<refundable type="boolean">false</refundable>
<created_at type="datetime">2011-08-25T12:00:00Z</created_at>
<details>
<account>
<account_code>1</account_code>
<state>active</state>
<username nil="nil"></username>
<email>[email protected]</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<company_name></company_name>
<vat_number nil="nil"></vat_number>
<tax_exempt type="boolean">false</tax_exempt>
<address>
<address1>123 Main St.</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94105</zip>
<country>US</country>
<phone nil="nil"></phone>
</address>
</account>
</details>
<a name="refund" href="https://api.recurly.com/v2/transactions/abcdef1234567890" method="delete"/>
<action_result>example</action_result>
</transaction>
3 changes: 2 additions & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @property Recurly_BillingInfo $billing_info
* @property-read string $state On of active, canceled, future, expired, paused
* @property-read Recurly_Subscription $pending_subscription Nested information about a pending subscription change at renewal
* @property string $action_result
*/
class Recurly_Subscription extends Recurly_Resource
{
Expand Down Expand Up @@ -339,7 +340,7 @@ protected function getWriteableAttributes() {
'remaining_pause_cycles', 'custom_fields', 'auto_renew',
'renewal_billing_cycles', 'gateway_code', 'shipping_method_code',
'shipping_amount_in_cents', 'transaction_type', 'tax_inclusive',
'ramp_intervals'
'ramp_intervals', 'action_result'
);
}
}
3 changes: 2 additions & 1 deletion lib/recurly/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @property string $message The message from the gateway
* @property string $description The description that gets sent to the gateway, if applicable.
* @property null|Recurly_TransactionError $transaction_error
* @property string $action_result
*/
class Recurly_Transaction extends Recurly_Resource
{
Expand Down Expand Up @@ -111,7 +112,7 @@ protected function getNodeName() {
protected function getWriteableAttributes() {
return array(
'account', 'amount_in_cents', 'currency', 'description', 'accounting_code',
'tax_exempt', 'tax_code', 'product_code', 'payment_method', 'collected_at'
'tax_exempt', 'tax_code', 'product_code', 'payment_method', 'collected_at', 'action_result'
);
}
}

0 comments on commit f196298

Please sign in to comment.