-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recurring application charges and tests
- Loading branch information
Showing
6 changed files
with
280 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Dan\Shopify\Helpers; | ||
|
||
class RecurringApplicationCharges extends Endpoint | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Dan\Shopify\Models; | ||
|
||
class RecurringApplicationCharge extends AbstractModel | ||
{ | ||
/** | ||
* Constant representing an active subscription status. | ||
*/ | ||
public const ACTIVE = 'active'; | ||
|
||
/** | ||
* Constant representing a cancelled subscription status. | ||
*/ | ||
public const CANCELLED = 'cancelled'; | ||
|
||
/** | ||
* Constant representing a declined subscription status. | ||
*/ | ||
public const DECLINED = 'declined'; | ||
|
||
/** | ||
* Constant representing an expired subscription status. | ||
*/ | ||
public const EXPIRED = 'expired'; | ||
|
||
/** | ||
* Constant representing a frozen subscription status. | ||
*/ | ||
public const FROZEN = 'frozen'; | ||
|
||
/** | ||
* Constant representing a pending subscription status. | ||
*/ | ||
public const PENDING = 'pending'; | ||
|
||
/** @var string */ | ||
public static $resource_name = 'recurring_application_charge'; | ||
|
||
/** @var string */ | ||
public static $resource_name_many = 'recurring_application_charges'; | ||
|
||
/** | ||
* The recurring application charge statuses. | ||
* | ||
* @var string[] | ||
*/ | ||
public static $statuses = [ | ||
self::ACTIVE, self::CANCELLED, self::DECLINED, | ||
self::FROZEN, self::EXPIRED, self::PENDING, | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'activated_on' => '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', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Dan\Shopify\Test; | ||
|
||
use Carbon\Carbon; | ||
use PHPUnit\Framework\TestCase; | ||
use Dan\Shopify\Models\RecurringApplicationCharge; | ||
|
||
class RecurringApplicationChargeTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_casts_all_attributes_to_their_native_types() | ||
{ | ||
$model = $this->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' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Dan\Shopify\Test; | ||
|
||
use Throwable; | ||
use Dan\Shopify\Shopify; | ||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class RecurringApplicationChargesApiTest extends TestCase | ||
{ | ||
/** | ||
* Create a new recurring application charge. | ||
* | ||
* @test | ||
* @throws Throwable | ||
*/ | ||
public function it_creates_a_new_recurring_application_charge(): void | ||
{ | ||
Http::fake([ | ||
'*admin/recurring_application_charges.json' => $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', | ||
]; | ||
} | ||
} |