From e9ca04e245a03085efbe6b11ded010bf504d8d53 Mon Sep 17 00:00:00 2001 From: Flavio Muller Date: Tue, 26 Mar 2024 15:58:59 -0400 Subject: [PATCH] Add net_terms_type to Invoices, Purchases, and Subscriptions --- Tests/Recurly/Invoice_Test.php | 18 +++ Tests/Recurly/Purchase_Test.php | 14 +- Tests/Recurly/Subscription_Test.php | 34 ++++- .../create-201-with-eom-net-terms.xml | 20 +++ .../create-201-with-eom-net-terms.xml | 144 ++++++++++++++++++ lib/recurly/invoice.php | 5 +- lib/recurly/purchase.php | 3 +- lib/recurly/subscription.php | 3 +- 8 files changed, 235 insertions(+), 6 deletions(-) create mode 100644 Tests/fixtures/invoices/create-201-with-eom-net-terms.xml create mode 100644 Tests/fixtures/purchases/create-201-with-eom-net-terms.xml diff --git a/Tests/Recurly/Invoice_Test.php b/Tests/Recurly/Invoice_Test.php index b93206a3..ae3c807e 100644 --- a/Tests/Recurly/Invoice_Test.php +++ b/Tests/Recurly/Invoice_Test.php @@ -219,4 +219,22 @@ public function testGetInvoiceWithCustomFields() { $this->assertEquals(sizeof($line_item->custom_fields), 1); } } + + public function testInvoiceWithEomNetTerms() { + $this->client->addResponse('POST', '/accounts/abcdef1234567890/invoices', 'invoices/create-201-with-eom-net-terms.xml'); + + $invoice = Recurly_Invoice::invoicePendingCharges('abcdef1234567890', array("net_terms" => 60), $this->client); + + $this->assertInstanceOf('Recurly_Invoice', $invoice); + $this->assertInstanceOf('Recurly_Stub', $invoice->account); + $this->assertEquals($invoice->uuid, '012345678901234567890123456789ab'); + $this->assertEquals($invoice->currency, 'USD'); + $this->assertEquals($invoice->total_in_cents, 300); + $this->assertEquals($invoice->getHref(),'https://api.recurly.com/v2/invoices/012345678901234567890123456789ab'); + $this->assertEquals($invoice->terms_and_conditions, 'Some Terms and Conditions'); + $this->assertEquals($invoice->customer_notes, 'Some Customer Notes'); + $this->assertEquals($invoice->vat_reverse_charge_notes, 'Some VAT Notes'); + $this->assertEquals($invoice->net_terms, 60); + $this->assertEquals($invoice->net_terms_type, 'eom'); + } } diff --git a/Tests/Recurly/Purchase_Test.php b/Tests/Recurly/Purchase_Test.php index 6f112005..c37442ef 100644 --- a/Tests/Recurly/Purchase_Test.php +++ b/Tests/Recurly/Purchase_Test.php @@ -169,9 +169,21 @@ public function testTransactionError() { 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); } + + public function testPurchaseWithEomNetTerms(){ + $this->client->addResponse('POST', '/purchases', 'purchases/create-201-with-eom-net-terms.xml'); + + $purchase = $this->mockPurchase(); + $purchase->net_terms = 30; + $purchase->net_terms_type = "eom"; + $collection = Recurly_Purchase::invoice($purchase, $this->client); + + $this->assertInstanceOf('Recurly_InvoiceCollection', $collection); + $this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice); + } } diff --git a/Tests/Recurly/Subscription_Test.php b/Tests/Recurly/Subscription_Test.php index 218b9d3e..82e52727 100644 --- a/Tests/Recurly/Subscription_Test.php +++ b/Tests/Recurly/Subscription_Test.php @@ -630,7 +630,7 @@ public function testConvertTrialWithout3DSToken() { } public function testPreviewNewSubscriptionWithActionResult(){ - + $this->client->addResponse('POST', '/subscriptions/preview', 'subscriptions/preview-200-new-with-action-result.xml'); $subscription = new Recurly_Subscription(null, $this->client); @@ -641,4 +641,36 @@ public function testPreviewNewSubscriptionWithActionResult(){ $subscription->preview(); $this->assertEquals('example', $subscription->action_result); } + + public function testSubscriptionWithEomNetTerms() { + $subscription = new Recurly_Subscription(); + $subscription->plan_code = 'gold'; + $subscription->currency = 'USD'; + $subscription->net_terms = 10; + $subscription->net_terms_type = 'eom'; + $subscription->collection_method = 'automatic'; + $subscription->po_number = '1000'; + $subscription->imported_trial = true; + + $account = new Recurly_Account(); + $account->account_code = '123'; + + $subscription->account = $account; + + $this->assertXmlStringEqualsXmlString( + " + + 123 + + gold + USD + + 10 + eom + 1000 + automatic + true + ", $subscription->xml()); + + } } diff --git a/Tests/fixtures/invoices/create-201-with-eom-net-terms.xml b/Tests/fixtures/invoices/create-201-with-eom-net-terms.xml new file mode 100644 index 00000000..09e0a950 --- /dev/null +++ b/Tests/fixtures/invoices/create-201-with-eom-net-terms.xml @@ -0,0 +1,20 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/invoices/created-invoice + + + + + 012345678901234567890123456789ab + pending + 1000 + + USD + 60 + eom + 300 + 300 + Some Terms and Conditions + Some Customer Notes + Some VAT Notes + diff --git a/Tests/fixtures/purchases/create-201-with-eom-net-terms.xml b/Tests/fixtures/purchases/create-201-with-eom-net-terms.xml new file mode 100644 index 00000000..d4d0bb49 --- /dev/null +++ b/Tests/fixtures/purchases/create-201-with-eom-net-terms.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 + + + + 30 + eom + 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 + + +
+
+
+ +
+
diff --git a/lib/recurly/invoice.php b/lib/recurly/invoice.php index 6ca350c8..f5570ed5 100644 --- a/lib/recurly/invoice.php +++ b/lib/recurly/invoice.php @@ -36,7 +36,8 @@ * @property string $tax_type * @property string $tax_region * @property float $tax_rate - * @property int $net_terms + * @property int $net_terms The net terms of the invoice. + * @property string $net_terms_type The net terms type of the invoice. accepted_values: "net", "eom". * @property string $collection_method * @property Recurly_Stub $redemptions * @property Recurly_Adjustment[] $line_items @@ -246,7 +247,7 @@ protected function getNodeName() { protected function getWriteableAttributes() { return array( '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', + 'collection_method', 'net_terms', 'net_terms_type', 'po_number', 'currency', 'credit_customer_notes', 'gateway_code' ); } diff --git a/lib/recurly/purchase.php b/lib/recurly/purchase.php index e47a5780..80f904b1 100644 --- a/lib/recurly/purchase.php +++ b/lib/recurly/purchase.php @@ -8,6 +8,7 @@ * @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. + * @property string $net_terms_type The net terms type of the invoice. accepted_values: "net", "eom". * @property string[] $coupon_codes An array of coupon codes to apply to the purchase. * @property Recurly_Subscription[] $subscriptions An array of subscriptions to apply to the purchase. * @property Recurly_GiftCard $gift_card A gift card to apply to the purchase. @@ -117,7 +118,7 @@ protected function getNodeName() { protected function getWriteableAttributes() { return array( 'account', 'adjustments', 'billing_info_uuid', 'collection_method', 'currency', 'po_number', - 'net_terms', 'subscriptions', 'gift_card', 'coupon_codes', 'customer_notes', + 'net_terms', 'net_terms_type', '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 50af2bbc..afc64f69 100644 --- a/lib/recurly/subscription.php +++ b/lib/recurly/subscription.php @@ -22,6 +22,7 @@ * @property float $tax_rate Tax rate that will be applied to this subscription * @property string $collection_method Optional field to set the collection for an invoice as automatic or manual. The default is automatic if it's not set. * @property integer $net_terms Integer representing the number of days after an invoice's creation that the invoice will become past due. If an invoice's net terms are set to 0, it is due 'On Receipt' and will become past due 24 hours after it’s created. If an invoice is due net 30, it will become past due at 31 days exactly. Defaults to 0. + * @property string $net_terms_type The net terms type of the invoice. accepted_values: "net", "eom". * @property string $po_number Optional notes field. Attach a PO number to the invoice. * @property boolean $bulk Optional field to be used only when needing to bypass the 60 second limit on creating subscriptions. Should only be used when creating subscriptions in bulk from the API. Set to 'true' or 'false'. Defaults to 'false'. * @property string $terms_and_conditions Optional notes field. This will default to the Terms and Conditions text specified on the Invoice Settings page in your Recurly admin. Specify custom notes with this tag to add or override Terms and Conditions. Custom notes will stay with a subscription on all renewals. @@ -332,7 +333,7 @@ protected function getWriteableAttributes() { 'account', 'billing_info', 'plan_code', 'coupon_code', 'coupon_codes', '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', + 'timeframe', 'subscription_add_ons', 'net_terms', 'net_terms_type', 'po_number', 'collection_method', 'cost_in_cents', 'remaining_billing_cycles', 'bulk', 'terms_and_conditions', 'customer_notes', 'vat_reverse_charge_notes', 'bank_account_authorized_at', 'revenue_schedule_type', 'gift_card',