From 4daf544314d04489b9cc5202cd3a8eaa944f3de8 Mon Sep 17 00:00:00 2001 From: Felipe Kosouski Date: Fri, 4 Aug 2023 14:02:31 -0300 Subject: [PATCH] add action_result to subscription & trx --- Tests/Recurly/Purchase_Test.php | 9 ++ Tests/Recurly/Subscription_Test.php | 13 ++ Tests/Recurly/Transaction_Test.php | 8 + .../create-with-action-result-201.xml | 144 ++++++++++++++++++ .../preview-200-new-with-action-result.xml | 28 ++++ .../create-with-action-result-200.xml | 46 ++++++ lib/recurly/subscription.php | 3 +- lib/recurly/transaction.php | 3 +- 8 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 Tests/fixtures/purchases/create-with-action-result-201.xml create mode 100644 Tests/fixtures/subscriptions/preview-200-new-with-action-result.xml create mode 100644 Tests/fixtures/transactions/create-with-action-result-200.xml diff --git a/Tests/Recurly/Purchase_Test.php b/Tests/Recurly/Purchase_Test.php index fafb7ec4..6f112005 100644 --- a/Tests/Recurly/Purchase_Test.php +++ b/Tests/Recurly/Purchase_Test.php @@ -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'), @@ -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); + } } diff --git a/Tests/Recurly/Subscription_Test.php b/Tests/Recurly/Subscription_Test.php index 4410bb09..218b9d3e 100644 --- a/Tests/Recurly/Subscription_Test.php +++ b/Tests/Recurly/Subscription_Test.php @@ -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); + } } diff --git a/Tests/Recurly/Transaction_Test.php b/Tests/Recurly/Transaction_Test.php index 322620d6..3e09f42c 100644 --- a/Tests/Recurly/Transaction_Test.php +++ b/Tests/Recurly/Transaction_Test.php @@ -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); + } } diff --git a/Tests/fixtures/purchases/create-with-action-result-201.xml b/Tests/fixtures/purchases/create-with-action-result-201.xml new file mode 100644 index 00000000..8d54ee7d --- /dev/null +++ b/Tests/fixtures/purchases/create-with-action-result-201.xml @@ -0,0 +1,144 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/invoices/3704 + + + + + +
+ 400 Alabama St + + San Francisco + CA + 94110 + US + +
+ 3d8648fcf2be67ed304ff242d6bbb9d4 + paid + + 3704 + + + 1000 + 0 + 1000 + 1000 + USD + 2017-05-17T17:38:55Z + 2017-05-17T17:38:55Z + + 2017-05-17T17:38:55Z + + + + 0 + automatic + + + + + 3d8648fced80685b7f165a43fca65cda + invoiced + + + 4549449c-5870-4845-b672-1d07f15e87dd + debit + 1000 + 1 + 0 + 0 + 1000 + USD + false + false + + 2017-05-17T17:38:55Z + + 2017-05-17T17:38:55Z + 2017-05-17T17:38:55Z + at_invoice + + Dolores + Du Monde + 400 Dolores St + + San Francisco + CA + 94110 + US + Home + + + + size + small + + + + + + + + + 3d8648fd0cc7c6e9196b944878afcd3d + purchase + 1000 + 0 + USD + success + credit_card + 135998 + transaction + false + true + true + true + + test + api + + Successful test transaction + + + + + Street address and postal code match. + + + 2017-05-17T17:38:55Z + 2017-05-17T17:38:55Z + 2017-05-17T17:38:55Z +
+ + 6b97ec05-7e9d-4506-a4b6-5459acbd6403 + + + + + + Benjamin + Du Monde + 400 Alabama St + + San Francisco + CA + 94110 + US + + + Visa + 2019 + 12 + 411111 + 1111 + + +
+ example +
+
+ +
+
diff --git a/Tests/fixtures/subscriptions/preview-200-new-with-action-result.xml b/Tests/fixtures/subscriptions/preview-200-new-with-action-result.xml new file mode 100644 index 00000000..123316d2 --- /dev/null +++ b/Tests/fixtures/subscriptions/preview-200-new-with-action-result.xml @@ -0,0 +1,28 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + gold + gold + + 012345678901234567890123456789ab + pending + 10000 + USD + 1 + + + + + + 2014-05-16T20:39:21Z + 2014-05-16T20:39:21Z + + + 10000 + + + example + diff --git a/Tests/fixtures/transactions/create-with-action-result-200.xml b/Tests/fixtures/transactions/create-with-action-result-200.xml new file mode 100644 index 00000000..3bd8a45b --- /dev/null +++ b/Tests/fixtures/transactions/create-with-action-result-200.xml @@ -0,0 +1,46 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + a13acd8fe4294916b79aec87b7ea441f + purchase + 100 + 0 + USD + success + check + + transaction + false + true + true + false + 2011-08-25T12:00:00Z +
+ + 1 + active + + verena@example.com + Verena + Example + + + false +
+ 123 Main St. + + San Francisco + CA + 94105 + US + +
+
+
+
+ example + diff --git a/lib/recurly/subscription.php b/lib/recurly/subscription.php index b473edf1..50af2bbc 100644 --- a/lib/recurly/subscription.php +++ b/lib/recurly/subscription.php @@ -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 { @@ -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' ); } } diff --git a/lib/recurly/transaction.php b/lib/recurly/transaction.php index 00f9beb3..ed51c054 100644 --- a/lib/recurly/transaction.php +++ b/lib/recurly/transaction.php @@ -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 { @@ -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' ); } }