Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 24afabd

Browse files
authored
Added BLADE billing redirect fix (#1263)
1 parent 695f968 commit 24afabd

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Diff for: src/Traits/BillingController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ public function process(
9191
);
9292

9393
// Go to homepage of app
94-
return Redirect::route(Util::getShopifyConfig('route_names.home'), [
94+
return Redirect::route(Util::getShopifyConfig('route_names.home'), array_merge([
9595
'shop' => $shop->getDomain()->toNative(),
96+
], Util::useNativeAppBridge() ? [] : [
9697
'host' => base64_encode($shop->getDomain()->toNative().'/admin'),
9798
'billing' => $result ? 'success' : 'failure',
98-
])->with(
99+
]))->with(
99100
$result ? 'success' : 'failure',
100101
'billing'
101102
);

Diff for: tests/Traits/BillingControllerTest.php

+41-1
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ public function testSendsShopToBillingScreen(): void
5151
);
5252
}
5353

54-
public function testShopAcceptsBilling(): void
54+
public function testReactFrontendShopAcceptsBilling(): void
5555
{
5656
// Stub the responses
5757
ApiStub::stubResponses([
5858
'post_recurring_application_charges',
5959
'post_recurring_application_charges_activate',
6060
]);
6161

62+
config(['shopify-app.frontend_engine' => 'REACT']);
63+
6264
// Create the shop and log them in
6365
$shop = factory($this->model)->create();
6466
$this->auth->login($shop);
@@ -87,6 +89,44 @@ public function testShopAcceptsBilling(): void
8789
$this->assertNotNull($shop->plan);
8890
}
8991

92+
public function testBladeFrontendShopAcceptsBilling(): void
93+
{
94+
// Stub the responses
95+
ApiStub::stubResponses([
96+
'post_recurring_application_charges',
97+
'post_recurring_application_charges_activate',
98+
]);
99+
100+
config(['shopify-app.frontend_engine' => 'BLADE']);
101+
102+
// Create the shop and log them in
103+
$shop = factory($this->model)->create();
104+
$this->auth->login($shop);
105+
106+
// Make the plan
107+
$plan = factory(Util::getShopifyConfig('models.plan', Plan::class))->states('type_recurring')->create();
108+
109+
// Run the call
110+
$response = $this->call(
111+
'get',
112+
"/billing/process/{$plan->id}",
113+
[
114+
'charge_id' => 1,
115+
'shop' => $shop->getDomain()->toNative(),
116+
]
117+
);
118+
119+
// Refresh the model
120+
$shop->refresh();
121+
122+
$hostValue = urlencode(base64_encode($shop->getDomain()->toNative().'/admin'));
123+
// Assert we've redirected and shop has been updated
124+
$response->assertRedirect();
125+
$this->assertFalse(Str::contains($response->headers->get('Location'), '&host='.$hostValue));
126+
$this->assertFalse(Str::contains($response->headers->get('Location'), '&billing=success'));
127+
$this->assertNotNull($shop->plan);
128+
}
129+
90130
public function testUsageChargeSuccess(): void
91131
{
92132
// Stub the responses

0 commit comments

Comments
 (0)