From 748fc4a4719377754a8eb01325c850334595776d Mon Sep 17 00:00:00 2001 From: Erik Galloway <8866568+erikgall@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:13:00 -0500 Subject: [PATCH 1/2] Bump PHP min version to 7.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 225a52e..c569927 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } }, "require": { - "php": ">=7.0", + "php": ">=7.1", "guzzlehttp/guzzle": "^6.2|^7.0", "nesbot/carbon": "^1.26.3 || ^2.0", "illuminate/http": "^8.83", From 8ab0aa9ec426f149eec7257e24f1464a84edd4d6 Mon Sep 17 00:00:00 2001 From: Erik Galloway <8866568+erikgall@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:14:09 -0500 Subject: [PATCH 2/2] Add recurring application charges and tests --- src/Helpers/Endpoint.php | 1 + src/Helpers/RecurringApplicationCharges.php | 8 ++ src/Models/RecurringApplicationCharge.php | 76 ++++++++++++++ src/Shopify.php | 69 +++++++------ tests/RecurringApplicationChargeTest.php | 55 ++++++++++ tests/RecurringApplicationChargesApiTest.php | 103 +++++++++++++++++++ 6 files changed, 280 insertions(+), 32 deletions(-) create mode 100644 src/Helpers/RecurringApplicationCharges.php create mode 100644 src/Models/RecurringApplicationCharge.php create mode 100644 tests/RecurringApplicationChargeTest.php create mode 100644 tests/RecurringApplicationChargesApiTest.php diff --git a/src/Helpers/Endpoint.php b/src/Helpers/Endpoint.php index 719b9f7..fb04c0e 100644 --- a/src/Helpers/Endpoint.php +++ b/src/Helpers/Endpoint.php @@ -28,6 +28,7 @@ abstract class Endpoint 'orders', 'price_rules', 'products', + 'recurring_application_charges', 'risks', 'smart_collections', 'themes', diff --git a/src/Helpers/RecurringApplicationCharges.php b/src/Helpers/RecurringApplicationCharges.php new file mode 100644 index 0000000..2f77ac6 --- /dev/null +++ b/src/Helpers/RecurringApplicationCharges.php @@ -0,0 +1,8 @@ + 'datetime', + 'billing_on' => 'datetime', + 'cancelled_on' => 'datetime', + 'capped_amount' => 'float', + 'confirmation_url' => 'string', + 'created_at' => 'datetime', + 'id' => 'integer', + 'name' => 'string', + 'price' => 'float', + 'return_url' => 'string', + 'status' => 'string', + 'terms' => 'string', + 'test' => 'bool', + 'trial_days' => 'integer', + 'trial_ends_on' => 'datetime', + 'updated_at' => 'datetime', + ]; +} diff --git a/src/Shopify.php b/src/Shopify.php index ddf0f0e..3be108d 100644 --- a/src/Shopify.php +++ b/src/Shopify.php @@ -3,6 +3,7 @@ namespace Dan\Shopify; use BadMethodCallException; +use Dan\Shopify\Models\RecurringApplicationCharge; use Dan\Shopify\Exceptions\InvalidOrMissingEndpointException; use Dan\Shopify\Exceptions\ModelNotFoundException; use Dan\Shopify\Helpers\Endpoint; @@ -44,6 +45,7 @@ * @property \Dan\Shopify\Helpers\Products $products * @property \Dan\Shopify\Helpers\SmartCollections $smart_collections * @property \Dan\Shopify\Helpers\Themes $themes + * @property \Dan\Shopify\Helpers\RecurringApplicationCharges $recurring_application_charges * @property \Dan\Shopify\Helpers\Risks $risks * @property \Dan\Shopify\Helpers\Variants $variants * @property \Dan\Shopify\Helpers\Webhooks $webhooks @@ -57,6 +59,7 @@ * @method \Dan\Shopify\Helpers\Orders orders(string $order_id) * @method \Dan\Shopify\Helpers\PriceRules price_rules(string $price_rule_id) * @method \Dan\Shopify\Helpers\Products products(string $product_id) + * @method \Dan\Shopify\Helpers\RecurringApplicationCharges recurring_application_charges(string $charge_id) * @method \Dan\Shopify\Helpers\Risks risks(string $risk_id) * @method \Dan\Shopify\Helpers\SmartCollections smart_collections(string $smart_collection_id) * @method \Dan\Shopify\Helpers\Themes themes(string $theme_id) @@ -168,42 +171,44 @@ class Shopify * @var array */ protected static $endpoints = [ - 'assets' => 'assets.json', - 'customers' => 'customers/%s.json', - 'discount_codes' => 'discount_codes/%s.json', - 'disputes' => 'shopify_payments/disputes/%s.json', - 'fulfillments' => 'fulfillments/%s.json', - 'fulfillment_services' => 'fulfillment_services/%s.json', - 'images' => 'images/%s.json', - 'metafields' => 'metafields/%s.json', - 'orders' => 'orders/%s.json', - 'price_rules' => 'price_rules/%s.json', - 'products' => 'products/%s.json', - 'risks' => 'risks/%s.json', - 'smart_collections' => 'smart_collections/%s.json', - 'themes' => 'themes/%s.json', - 'variants' => 'variants/%s.json', - 'webhooks' => 'webhooks/%s.json', + 'assets' => 'assets.json', + 'customers' => 'customers/%s.json', + 'discount_codes' => 'discount_codes/%s.json', + 'disputes' => 'shopify_payments/disputes/%s.json', + 'fulfillments' => 'fulfillments/%s.json', + 'fulfillment_services' => 'fulfillment_services/%s.json', + 'images' => 'images/%s.json', + 'metafields' => 'metafields/%s.json', + 'orders' => 'orders/%s.json', + 'price_rules' => 'price_rules/%s.json', + 'products' => 'products/%s.json', + 'recurring_application_charges' => 'recurring_application_charges/%s.json', + 'risks' => 'risks/%s.json', + 'smart_collections' => 'smart_collections/%s.json', + 'themes' => 'themes/%s.json', + 'variants' => 'variants/%s.json', + 'webhooks' => 'webhooks/%s.json', ]; /** @var array $resource_models */ protected static $resource_models = [ - 'assets' => Asset::class, - 'customers' => Customer::class, - 'discount_codes' => DiscountCode::class, - 'disputes' => Dispute::class, - 'fulfillments' => Fulfillment::class, - 'fulfillment_services' => FulfillmentService::class, - 'images' => Image::class, - 'metafields' => Metafield::class, - 'orders' => Order::class, - 'price_rules' => PriceRule::class, - 'products' => Product::class, - 'risks' => Risk::class, - 'smart_collections' => SmartCollections::class, - 'themes' => Theme::class, - 'variants' => Variant::class, - 'webhooks' => Webhook::class, + 'assets' => Asset::class, + 'customers' => Customer::class, + 'discount_codes' => DiscountCode::class, + 'disputes' => Dispute::class, + 'fulfillments' => Fulfillment::class, + 'fulfillment_services' => FulfillmentService::class, + 'images' => Image::class, + 'metafields' => Metafield::class, + 'orders' => Order::class, + 'price_rules' => PriceRule::class, + 'products' => Product::class, + 'recurring_application_charges' => RecurringApplicationCharge::class, + 'risks' => Risk::class, + 'smart_collections' => SmartCollections::class, + 'themes' => Theme::class, + 'variants' => Variant::class, + 'webhooks' => Webhook::class, ]; /** @var array $cursored_enpoints */ diff --git a/tests/RecurringApplicationChargeTest.php b/tests/RecurringApplicationChargeTest.php new file mode 100644 index 0000000..55b38a4 --- /dev/null +++ b/tests/RecurringApplicationChargeTest.php @@ -0,0 +1,55 @@ +getModel(); + + $this->assertIsFloat($model->capped_amount); + $this->assertIsInt($model->id); + $this->assertIsFloat($model->price); + $this->assertIsInt($model->trial_days); + + $this->assertInstanceOf(Carbon::class, $model->activated_on); + $this->assertInstanceOf(Carbon::class, $model->billing_on); + $this->assertInstanceOf(Carbon::class, $model->cancelled_on); + $this->assertInstanceOf(Carbon::class, $model->created_at); + $this->assertInstanceOf(Carbon::class, $model->trial_ends_on); + $this->assertInstanceOf(Carbon::class, $model->updated_at); + } + + /** + * Make a new RecurringApplicationCharge instance. + * + * @return \Dan\Shopify\Models\RecurringApplicationCharge + */ + protected function getModel() + { + return new RecurringApplicationCharge([ + 'activated_on' => '2022-09-20T12:00:00-00:00', + 'billing_on' => '2022-09-28T12:00:00-00:00', + 'cancelled_on' => '2022-09-30T12:00:00-00:00', + 'capped_amount' => "100", + 'confirmation_url' => "https://jsmith.myshopify.com/admin/charges/confirm_recurring_application_charge?id=654381177&signature=BAhpBHkQASc%3D--374c02da2ea0371b23f40781b8a6d5f4a520e77b", + 'created_at' => '2022-09-20T12:00:00-00:00', + 'id' => 675931192, + 'name' => "Super Duper Expensive action", + 'price' => "100.00", + 'return_url' => "http://super-duper.shopifyapps.com", + 'status' => "accepted", + 'terms' => "$1 for 1000 emails", + 'test' => null, + 'trial_days' => 7, + 'trial_ends_on' => '2022-09-27T12:00:00-00:00', + 'updated_at' => '2022-09-20T12:00:00-00:00' + ]); + } +} diff --git a/tests/RecurringApplicationChargesApiTest.php b/tests/RecurringApplicationChargesApiTest.php new file mode 100644 index 0000000..71e4a01 --- /dev/null +++ b/tests/RecurringApplicationChargesApiTest.php @@ -0,0 +1,103 @@ + $this->getResource(), + ]); + + $response = (new Shopify('shop', 'token'))->recurring_application_charges->post([ + 'name' => 'Charge Name', + 'price' => 15.99, + 'return_url' => 'https://phpunit-store.myshopifyapps.com', + 'test' => true, + ]); + + Http::assertSent(function (Request $request) { + return $request->url() == 'https://shop.myshopify.com/admin/recurring_application_charges.json' + && $request->method() == 'POST'; + }); + + $this->assertEquals(123, $response['id']); + $this->assertEquals('Charge Name', $response['name']); + } + + /** + * Get a list of recurring application charges. + * + * @test + * @throws Throwable + */ + public function it_gets_a_list_of_orders(): void + { + Http::fake(); + + (new Shopify('shop', 'token'))->recurring_application_charges->get(); + + Http::assertSent(function (Request $request) { + return $request->url() == 'https://shop.myshopify.com/admin/recurring_application_charges.json' + && $request->method() == 'GET'; + }); + } + + /** + * Fetch a recurring application charge by id. + * + * @test + * @throws Throwable + */ + public function it_gets_a_recurring_application_charge(): void + { + Http::fake(); + + (new Shopify('shop', 'token'))->recurring_application_charges->find(123); + + Http::assertSent(function (Request $request) { + return $request->url() == 'https://shop.myshopify.com/admin/recurring_application_charges/123.json' + && $request->method() == 'GET'; + }); + } + + /** + * Get the resource response data for a recurring application charge. + * + * @return array + */ + protected function getResource() + { + return [ + 'activated_on' => '2022-09-20T12:00:00-00:00', + 'billing_on' => '2022-09-28T12:00:00-00:00', + 'cancelled_on' => '2022-09-30T12:00:00-00:00', + 'capped_amount' => '100', + 'confirmation_url' => 'https://jsmith.myshopify.com/admin/charges/confirm_recurring_application_charge?id=654381177&signature=BAhpBHkQASc%3D--374c02da2ea0371b23f40781b8a6d5f4a520e77b', + 'created_at' => '2022-09-20T12:00:00-00:00', + 'id' => 123, + 'name' => 'Charge Name', + 'price' => '100.00', + 'return_url' => 'http://super-duper.shopifyapps.com', + 'status' => 'accepted', + 'terms' => '$1 for 1000 emails', + 'test' => null, + 'trial_days' => 7, + 'trial_ends_on' => '2022-09-27T12:00:00-00:00', + 'updated_at' => '2022-09-20T12:00:00-00:00', + ]; + } +}