Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Actions/ActivatePlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct(
*
* @return ChargeId
*/
public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $chargeRef): ChargeId
public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $chargeRef, string $host): ChargeId
{
// Get the shop
$shop = $this->shopQuery->getById($shopId);
Expand Down Expand Up @@ -136,7 +136,7 @@ public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $charge
$transfer->billingOn = null;
$transfer->trialEndsOn = null;
}
$transfer->planDetails = $this->chargeHelper->details($plan, $shop);
$transfer->planDetails = $this->chargeHelper->details($plan, $shop, $host);

// Create the charge
$charge = $this->chargeCommand->make($transfer);
Expand Down
6 changes: 3 additions & 3 deletions src/Actions/GetPlanUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(ChargeHelper $chargeHelper, IPlanQuery $planQuery, I
*
* @return string
*/
public function __invoke(ShopId $shopId, NullablePlanId $planId): string
public function __invoke(ShopId $shopId, NullablePlanId $planId, string $host): string
{
// Get the shop
$shop = $this->shopQuery->getById($shopId);
Expand All @@ -72,14 +72,14 @@ public function __invoke(ShopId $shopId, NullablePlanId $planId): string
// Confirmation URL
if ($plan->getInterval()->toNative() === ChargeInterval::ANNUAL()->toNative()) {
$api = $shop->apiHelper()
->createChargeGraphQL($this->chargeHelper->details($plan, $shop));
->createChargeGraphQL($this->chargeHelper->details($plan, $shop, $host));

$confirmationUrl = $api['confirmationUrl'];
} else {
$api = $shop->apiHelper()
->createCharge(
ChargeType::fromNative($plan->getType()->toNative()),
$this->chargeHelper->details($plan, $shop)
$this->chargeHelper->details($plan, $shop, $host)
);

$confirmationUrl = $api['confirmation_url'];
Expand Down
10 changes: 7 additions & 3 deletions src/Http/Middleware/VerifyShopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function handleInvalidShop(Request $request)
throw new HttpException('Shop is not installed or missing data.', Response::HTTP_FORBIDDEN);
}

return $this->installRedirect(ShopDomain::fromRequest($request));
return $this->installRedirect($request);
}

/**
Expand Down Expand Up @@ -300,6 +300,7 @@ protected function tokenRedirect(Request $request): RedirectResponse
Util::getShopifyConfig('route_names.authenticate.token'),
[
'shop' => ShopDomain::fromRequest($request)->toNative(),
'host' => $request->host ?? $request->host,
'target' => $target,
]
);
Expand All @@ -312,11 +313,14 @@ protected function tokenRedirect(Request $request): RedirectResponse
*
* @return RedirectResponse
*/
protected function installRedirect(ShopDomainValue $shopDomain): RedirectResponse
protected function installRedirect(Request $request): RedirectResponse
{
return Redirect::route(
Util::getShopifyConfig('route_names.authenticate'),
['shop' => $shopDomain->toNative()]
[
'shop' => ShopDomain::fromRequest($request)->toNative(),
'host' => $request->host ?? $request->host,
]
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Services/ChargeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function chargeForPlan(PlanId $planId, IShopModel $shop): ?ChargeModel
*
* @return PlanDetailsTransfer
*/
public function details(Plan $plan, IShopModel $shop): PlanDetailsTransfer
public function details(Plan $plan, IShopModel $shop, string $host): PlanDetailsTransfer
{
// Handle capped amounts for UsageCharge API
$isCapped = isset($plan->capped_amount) && $plan->capped_amount > 0;
Expand All @@ -267,7 +267,7 @@ public function details(Plan $plan, IShopModel $shop): PlanDetailsTransfer
$transfer->returnUrl = URL::secure(
Util::getShopifyConfig('billing_redirect'),
['plan' => $plan->getId()->toNative()]
).'?'.http_build_query(['shop' => $shop->getDomain()->toNative()]);
).'?'.http_build_query(['shop' => $shop->getDomain()->toNative(), 'host' => $host]);

return $transfer;
}
Expand Down
1 change: 1 addition & 0 deletions src/Traits/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function token(Request $request)
[
'shopDomain' => $shopDomain->toNative(),
'target' => $cleanTarget,
'host' => $request->host ?? $request->host
]
);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Traits/BillingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function index(
// Get the plan URL for redirect
$url = $getPlanUrl(
$shop->getId(),
NullablePlanId::fromNative($plan)
NullablePlanId::fromNative($plan),
$request->host
);

// Do a fullpage redirect
Expand Down Expand Up @@ -80,21 +81,24 @@ public function process(
if (!$request->has('charge_id')) {
return Redirect::route(Util::getShopifyConfig('route_names.home'), [
'shop' => $shop->getDomain()->toNative(),
'host' => base64_encode($shop->getDomain()->toNative().'/admin'),
'host' => $request->host ? $request->host : base64_encode($shop->getDomain()->toNative().'/admin')
]);
}
// Activate the plan and save
$result = $activatePlan(
$shop->getId(),
PlanId::fromNative($plan),
ChargeReference::fromNative((int) $request->query('charge_id'))
ChargeReference::fromNative((int) $request->query('charge_id')),
$request->host ? $request->host : base64_encode($shop->getDomain()->toNative().'/admin')
);

// Go to homepage of app
return Redirect::route(Util::getShopifyConfig('route_names.home'), array_merge([
'shop' => $shop->getDomain()->toNative(),
], Util::useNativeAppBridge() ? [] : [
'host' => base64_encode($shop->getDomain()->toNative().'/admin'),
], Util::useNativeAppBridge() ? [
'host' => $request->host ? $request->host : base64_encode($shop->getDomain()->toNative().'/admin')
] : [
'host' => $request->host ? $request->host : base64_encode($shop->getDomain()->toNative().'/admin'),
'billing' => $result ? 'success' : 'failure',
]))->with(
$result ? 'success' : 'failure',
Expand Down
1 change: 0 additions & 1 deletion src/resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
var createApp = AppBridge.default;
var app = createApp({
apiKey: "{{ \Osiset\ShopifyApp\Util::getShopifyConfig('api_key', $shopDomain ?? Auth::user()->name ) }}",
shopOrigin: "{{ $shopDomain ?? Auth::user()->name }}",
host: "{{ \Request::get('host') }}",
forceRedirect: true,
});
Expand Down