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

Update BillingController.php #1181

Merged
merged 8 commits into from
Sep 6, 2022
Merged
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
34 changes: 19 additions & 15 deletions src/Traits/BillingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ trait BillingController
/**
* Redirects to billing screen for Shopify.
*
* @param Request $request The request object.
* @param ShopQuery $shopQuery The shop querier.
* @param GetPlanUrl $getPlanUrl The action for getting the plan URL.
* @param int|null $plan The plan's ID, if provided in route.
* @param Request $request The request object.
* @param ShopQuery $shopQuery The shop querier.
* @param GetPlanUrl $getPlanUrl The action for getting the plan URL.
* @param int|null $plan The plan's ID, if provided in route.
*
* @return ViewView
*/
public function index(
Request $request,
ShopQuery $shopQuery,
Request $request,
ShopQuery $shopQuery,
GetPlanUrl $getPlanUrl,
?int $plan = null
?int $plan = null
): ViewView {
// Get the shop
$shop = $shopQuery->getByDomain(ShopDomain::fromNative($request->get('shop')));
Expand All @@ -59,22 +59,26 @@ public function index(
/**
* Processes the response from the customer.
*
* @param int $plan The plan's ID.
* @param Request $request The HTTP request object.
* @param ShopQuery $shopQuery The shop querier.
* @param int $plan The plan's ID.
* @param Request $request The HTTP request object.
* @param ShopQuery $shopQuery The shop querier.
* @param ActivatePlan $activatePlan The action for activating the plan for a shop.
*
* @return RedirectResponse
*/
public function process(
int $plan,
Request $request,
ShopQuery $shopQuery,
int $plan,
Request $request,
ShopQuery $shopQuery,
ActivatePlan $activatePlan
): RedirectResponse {
// Get the shop
$shop = $shopQuery->getByDomain(ShopDomain::fromNative($request->query('shop')));

if (!$request->has('charge_id')) {
return Redirect::route(Util::getShopifyConfig('route_names.home'), [
'shop' => $shop->getDomain()->toNative(),
]);
}
// Activate the plan and save
$result = $activatePlan(
$shop->getId(),
Expand All @@ -94,7 +98,7 @@ public function process(
/**
* Allows for setting a usage charge.
*
* @param StoreUsageCharge $request The verified request.
* @param StoreUsageCharge $request The verified request.
* @param ActivateUsageCharge $activateUsageCharge The action for activating a usage charge.
*
* @return RedirectResponse
Expand Down
19 changes: 19 additions & 0 deletions tests/Traits/BillingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,23 @@ public function testUsageChargeSuccess(): void
$response->assertRedirect('http://localhost');
$response->assertSessionHas('success');
}

public function testReturnToSettingScreenNoPlan()
{
// Set up a shop
$shop = factory($this->model)->create([
'plan_id' => null,
]);
//Log in
$this->auth->login($shop);
$url = 'https://example-app.com/billing/process/9999?shop='.$shop->name;
// Try to go to bill without a charge id which happens when you cancel the charge
$response = $this->call(
'get',
$url,
['shop' => $shop->name]
);
//Confirm we get sent back to the homepage of the app
$response->assertRedirect('https://example-app.com?shop='.$shop->name);
}
}