Skip to content

fix: Downgrading from an annual plan to a monthly plan results in the deferred cancellation of the merchant's current app subscription. #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 3 additions & 13 deletions src/Actions/GetPlanUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,10 @@ public function __invoke(ShopId $shopId, NullablePlanId $planId, string $host):
$plan = $planId->isNull() ? $this->planQuery->getDefault() : $this->planQuery->getById($planId);

// Confirmation URL
if ($plan->getInterval()->toNative() === ChargeInterval::ANNUAL()->toNative()) {
$api = $shop->apiHelper()
->createChargeGraphQL($this->chargeHelper->details($plan, $shop, $host));
$api = $shop->apiHelper()
->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, $host)
);

$confirmationUrl = $api['confirmation_url'];
}
$confirmationUrl = $api['confirmationUrl'];

return $confirmationUrl;
}
Expand Down
10 changes: 0 additions & 10 deletions src/Contracts/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ public function getCharge(ChargeType $chargeType, ChargeReference $chargeRef): R
*/
public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRef): ResponseAccess;

/**
* Create a charge.
*
* @param ChargeType $chargeType The type of charge (plural).
* @param PlanDetails $payload The data for the charge creation.
*
* @return ResponseAccess
*/
public function createCharge(ChargeType $chargeType, PlanDetails $payload): ResponseAccess;

/**
* Create a charge using GraphQL.
*
Expand Down
22 changes: 3 additions & 19 deletions src/Services/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,6 @@ public function activateCharge(ChargeType $chargeType, ChargeReference $chargeRe
return $response['body'][$typeString];
}

/**
* {@inheritdoc}
* TODO: Convert to GraphQL (merge createChargeGraphQL).
*/
public function createCharge(ChargeType $chargeType, PlanDetailsTransfer $payload): ResponseAccess
{
// API path
$typeString = $this->chargeApiPath($chargeType);

// Fire the request
$response = $this->doRequest(
ApiMethod::POST(),
"/admin/{$typeString}s.json",
[$typeString => $payload->toArray()]
);

return $response['body'][$typeString];
}

/**
* {@inheritdoc}
*
Expand All @@ -278,13 +259,15 @@ public function createChargeGraphQL(PlanDetailsTransfer $payload): ResponseAcces
mutation appSubscriptionCreate(
$name: String!,
$returnUrl: URL!,
$replacementBehavior: AppSubscriptionReplacementBehavior,
$trialDays: Int,
$test: Boolean,
$lineItems: [AppSubscriptionLineItemInput!]!
) {
appSubscriptionCreate(
name: $name,
returnUrl: $returnUrl,
replacementBehavior: $replacementBehavior,
trialDays: $trialDays,
test: $test,
lineItems: $lineItems
Expand All @@ -303,6 +286,7 @@ public function createChargeGraphQL(PlanDetailsTransfer $payload): ResponseAcces
$variables = [
'name' => $payload->name,
'returnUrl' => $payload->returnUrl,
'replacementBehavior' => 'APPLY_IMMEDIATELY',
'trialDays' => $payload->trialDays,
'test' => $payload->test,
'lineItems' => [
Expand Down
25 changes: 0 additions & 25 deletions tests/Services/ApiHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,6 @@ public function testActivateCharge(): void
$this->assertSame('Super Mega Plan', $data['name']);
}

public function testCreateCharge(): void
{
// Create a shop
$shop = factory($this->model)->create();

// Response stubbing
$this->setApiStub();
ApiStub::stubResponses(['post_recurring_application_charges']);

// Build the details object
$transfer = new PlanDetailsTransfer();
$transfer->name = 'Test';
$transfer->price = 12.00;
$transfer->interval = PlanInterval::EVERY_30_DAYS()->toNative();
$transfer->test = true;
$transfer->trialDays = 7;

$data = $shop->apiHelper()->createCharge(
ChargeType::RECURRING(),
$transfer
);
$this->assertInstanceOf(ResponseAccess::class, $data);
$this->assertSame('Basic Plan', $data['name']);
}

public function testGetWebhooks(): void
{
// Create a shop
Expand Down
Loading