Skip to content
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 @@ -136,16 +136,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 @@ -280,25 +280,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 @@ -310,13 +291,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 @@ -335,6 +318,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