Skip to content

Commit f145bc2

Browse files
committed
Merge branch 'master' into replace_rest_with_graphql_for_theme_level_support
2 parents 917cb23 + 52dabf2 commit f145bc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+519
-994
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- '8.1'
1515
- '8.2'
1616
- '8.3'
17+
- '8.4'
1718
analysis: [ false ]
1819
coverage: [ 'none' ]
1920
normalize: [ false ]
@@ -23,6 +24,7 @@ jobs:
2324
- '9.0'
2425
- '10.0'
2526
- '11.0.3'
27+
- '12.0'
2628
exclude:
2729
- php: '8.0'
2830
laravel: '9.0'
@@ -40,6 +42,8 @@ jobs:
4042
laravel: '8.22'
4143
- php: '8.3'
4244
laravel: '9.0'
45+
- php: '8.4'
46+
laravel: '12.0'
4347
include:
4448
- php: '8.0'
4549
laravel: '9.39.0'
@@ -80,7 +84,7 @@ jobs:
8084
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
8185

8286
- name: Cache composer dependencies
83-
uses: actions/cache@v2
87+
uses: actions/cache@v4
8488
with:
8589
path: ${{ steps.composer-cache.outputs.dir }}
8690
key: "php-${{ matrix.php }}-laravel-${{ matrix.laravel }}-${{ hashFiles('**/composer.json') }}"

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
composer install --no-interaction --prefer-dist
3232
3333
- name: Check for code style violation with PHP-CS-Fixer
34-
run: vendor/bin/php-cs-fixer fix --diff
34+
run: vendor/bin/php-cs-fixer check

.idea/laravel-shopify.iml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^8.0 || 8.1",
27+
"php": "^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4",
2828
"ext-json": "*",
2929
"funeralzone/valueobjects": "^0.5",
3030
"jenssegers/agent": "^2.6",
31-
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0",
31+
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0",
3232
"gnikyt/basic-shopify-api": "^9.0 || ^10.0 || ^11.0"
3333
},
3434
"require-dev": {
3535
"laravel/legacy-factories": "^v1.3.0",
3636
"ergebnis/composer-normalize": "^2.8",
3737
"friendsofphp/php-cs-fixer": "^3.0",
3838
"mockery/mockery": "^1.0",
39-
"orchestra/database": "~3.8 || ~4.0 || ~5.0 || ~6.0 || ~7.0",
40-
"orchestra/testbench": "~3.8 || ~4.0 || ~5.0 || ~6.0 || ~7.0 || ~8.0",
39+
"orchestra/database": "~3.8 || ~4.0 || ~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0",
40+
"orchestra/testbench": "~3.8 || ~4.0 || ~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0",
4141
"phpstan/phpstan": "^0.12",
42-
"phpunit/phpunit": "~8.0 || ^9.0 || ^10.0"
42+
"phpunit/phpunit": "~8.0 || ^9.0 || ^10.0 || ^11.0"
4343
},
4444
"config": {
4545
"sort-packages": true,

src/Actions/ActivatePlan.php

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,116 +18,45 @@
1818
use Osiset\ShopifyApp\Objects\Values\ShopId;
1919
use Osiset\ShopifyApp\Services\ChargeHelper;
2020

21-
/**
22-
* Activates a plan for a shop.
23-
*/
2421
class ActivatePlan
2522
{
2623
/**
27-
* The charge helper.
28-
*
29-
* @var ChargeHelper
30-
*/
31-
protected $chargeHelper;
32-
33-
/**
34-
* Action which cancels the current plan.
35-
*
36-
* @var callable
37-
*/
38-
protected $cancelCurrentPlan;
39-
40-
/**
41-
* Querier for shops.
42-
*
43-
* @var IShopQuery
44-
*/
45-
protected $shopQuery;
46-
47-
/**
48-
* Command for charges.
49-
*
50-
* @var IChargeCommand
51-
*/
52-
protected $chargeCommand;
53-
54-
/**
55-
* Command for shops.
56-
*
57-
* @var IShopCommand
58-
*/
59-
protected $shopCommand;
60-
61-
/**
62-
* Querier for plans.
63-
*
64-
* @var IPlanQuery
65-
*/
66-
protected $planQuery;
67-
68-
/**
69-
* Setup.
70-
*
71-
* @param callable $cancelCurrentPlanAction Action which cancels the current plan.
72-
* @param ChargeHelper $chargeHelper The charge helper.
73-
* @param IShopQuery $shopQuery The querier for shops.
74-
* @param IPlanQuery $planQuery The querier for plans.
75-
* @param IChargeCommand $chargeCommand The commands for charges.
76-
* @param IShopCommand $shopCommand The commands for shops.
77-
*
78-
* @return void
24+
* @param callable $cancelCurrentPlan
7925
*/
8026
public function __construct(
81-
callable $cancelCurrentPlanAction,
82-
ChargeHelper $chargeHelper,
83-
IShopQuery $shopQuery,
84-
IPlanQuery $planQuery,
85-
IChargeCommand $chargeCommand,
86-
IShopCommand $shopCommand
27+
protected $cancelCurrentPlan,
28+
protected ChargeHelper $chargeHelper,
29+
protected IShopQuery $shopQuery,
30+
protected IPlanQuery $planQuery,
31+
protected IChargeCommand $chargeCommand,
32+
protected IShopCommand $shopCommand
8733
) {
88-
$this->cancelCurrentPlan = $cancelCurrentPlanAction;
89-
$this->chargeHelper = $chargeHelper;
90-
$this->shopQuery = $shopQuery;
91-
$this->planQuery = $planQuery;
92-
$this->chargeCommand = $chargeCommand;
93-
$this->shopCommand = $shopCommand;
9434
}
9535

9636
/**
97-
* Execution.
9837
* TODO: Rethrow an API exception.
99-
*
100-
* @param ShopId $shopId The shop ID.
101-
* @param PlanId $planId The plan to use.
102-
* @param ChargeReference $chargeRef The charge ID from Shopify.
103-
*
104-
* @return ChargeId
10538
*/
10639
public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $chargeRef, string $host): ChargeId
10740
{
108-
// Get the shop
10941
$shop = $this->shopQuery->getById($shopId);
110-
111-
// Get the plan
11242
$plan = $this->planQuery->getById($planId);
11343
$chargeType = ChargeType::fromNative($plan->getType()->toNative());
11444

11545
// Activate the plan on Shopify
11646
$response = $shop->apiHelper()->activateCharge($chargeType, $chargeRef);
117-
11847
// Cancel the shop's current plan
11948
call_user_func($this->cancelCurrentPlan, $shopId);
120-
12149
// Cancel the existing charge if it exists (happens if someone refreshes during)
12250
$this->chargeCommand->delete($chargeRef, $shopId);
12351

124-
// Create the charge transfer
12552
$transfer = new ChargeTransfer();
12653
$transfer->shopId = $shopId;
12754
$transfer->planId = $planId;
12855
$transfer->chargeReference = $chargeRef;
12956
$transfer->chargeType = $chargeType;
13057
$transfer->chargeStatus = ChargeStatus::fromNative(strtoupper($response['status']));
58+
$transfer->planDetails = $this->chargeHelper->details($plan, $shop, $host);
59+
13160
if ($plan->isType(PlanType::RECURRING())) {
13261
$transfer->activatedOn = new Carbon($response['activated_on']);
13362
$transfer->billingOn = new Carbon($response['billing_on']);
@@ -137,9 +66,7 @@ public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $charge
13766
$transfer->billingOn = null;
13867
$transfer->trialEndsOn = null;
13968
}
140-
$transfer->planDetails = $this->chargeHelper->details($plan, $shop, $host);
14169

142-
// Create the charge
14370
$charge = $this->chargeCommand->make($transfer);
14471
$this->shopCommand->setToPlan($shopId, $planId);
14572

src/Actions/ActivateUsageCharge.php

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,45 @@
1313
use Osiset\ShopifyApp\Objects\Values\ShopId;
1414
use Osiset\ShopifyApp\Services\ChargeHelper;
1515

16-
/**
17-
* Activates a usage charge for a shop.
18-
*/
1916
class ActivateUsageCharge
2017
{
21-
/**
22-
* The helper for charges.
23-
*
24-
* @var ChargeHelper
25-
*/
26-
protected $chargeHelper;
27-
28-
/**
29-
* Command for charges.
30-
*
31-
* @var IChargeCommand
32-
*/
33-
protected $chargeCommand;
34-
35-
/**
36-
* Querier for shops.
37-
*
38-
* @var IShopQuery
39-
*/
40-
protected $shopQuery;
41-
42-
/**
43-
* Setup.
44-
*
45-
* @param ChargeHelper $chargeHelper The helper for charges.
46-
* @param IChargeCommand $chargeCommand The commands for charges.
47-
* @param IShopQuery $shopQuery The querier for shops.
48-
*
49-
* @return void
50-
*/
5118
public function __construct(
52-
ChargeHelper $chargeHelper,
53-
IChargeCommand $chargeCommand,
54-
IShopQuery $shopQuery
19+
protected ChargeHelper $chargeHelper,
20+
protected IChargeCommand $chargeCommand,
21+
protected IShopQuery $shopQuery
5522
) {
56-
$this->chargeHelper = $chargeHelper;
57-
$this->chargeCommand = $chargeCommand;
58-
$this->shopQuery = $shopQuery;
5923
}
6024

6125
/**
62-
* Execute.
6326
* TODO: Rethrow an API exception.
6427
*
65-
* @param ShopId $shopId The shop ID.
66-
* @param UsageChargeDetailsTransfer $ucd The usage charge details (without charge ID).
67-
*
6828
* @throws ChargeNotRecurringException
69-
*
70-
* @return ChargeId|bool
7129
*/
72-
public function __invoke(ShopId $shopId, UsageChargeDetailsTransfer $ucd)
30+
public function __invoke(ShopId $shopId, UsageChargeDetailsTransfer $ucd): ChargeId|bool
7331
{
74-
// Get the shop
7532
$shop = $this->shopQuery->getById($shopId);
76-
7733
// Ensure we have a recurring charge
7834
$currentCharge = $this->chargeHelper->chargeForPlan($shop->plan->getId(), $shop);
35+
7936
if (! $currentCharge->isType(ChargeType::RECURRING())) {
8037
throw new ChargeNotRecurringException('Can only create usage charges for recurring charge.');
8138
}
8239

8340
// Create the usage charge
8441
$ucd->chargeReference = $currentCharge->getReference();
8542
$response = $shop->apiHelper()->createUsageCharge($ucd);
43+
8644
if (! $response) {
8745
// Could not make usage charge, limit possibly reached
8846
return false;
8947
}
9048

91-
// Create the transfer
92-
$uct = new UsageChargeTransfer();
93-
$uct->shopId = $shopId;
94-
$uct->planId = $shop->plan->getId();
95-
$uct->chargeReference = ChargeReference::fromNative((int) $response['id']);
96-
$uct->details = $ucd;
49+
$transfer = new UsageChargeTransfer();
50+
$transfer->shopId = $shopId;
51+
$transfer->planId = $shop->plan->getId();
52+
$transfer->chargeReference = ChargeReference::fromNative((int) $response['id']);
53+
$transfer->details = $ucd;
9754

98-
// Save the usage charge
99-
return $this->chargeCommand->makeUsage($uct);
55+
return $this->chargeCommand->makeUsage($transfer);
10056
}
10157
}

0 commit comments

Comments
 (0)