Skip to content

Commit

Permalink
Support auth only and capture
Browse files Browse the repository at this point in the history
  • Loading branch information
philipxyc committed Feb 26, 2023
1 parent da5d9c8 commit 76130b8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions payments/StripeCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,55 @@ public function isApplicable($total, $host)
{
return $host->order_total <= $total;
}

public function capturePaymentIntent($paymentIntentId, $order, $data = [])
{
if ($order->payment !== $this->model->code)
return;

try {
$response = $this->createGateway()->paymentIntents->capture(
$paymentIntentId,
$data,
);

if ($response->status == 'succeeded') {
$order->logPaymentAttempt('Payment captured successfully', 1, $data, $response);
}
else {
$order->logPaymentAttempt('Payment captured failed', 0, $data, $response);
}

return $response;
}
catch (Exception $ex) {
$order->logPaymentAttempt('Payment capture failed -> '.$ex->getMessage(), 0, $data, $response);
}
}

public function cancelPaymentIntent($paymentIntentId, $order, $data = [])
{
if ($order->payment !== $this->model->code)
return;

try {
$response = $this->createGateway()->paymentIntents->cancel(
$paymentIntentId, $data
);

if ($response->status == 'canceled') {
$order->logPaymentAttempt('Payment canceled successfully', 1, $data, $response);
}
else {
$order->logPaymentAttempt('Payment canceled failed', 0, $data, $response);
}

return $response;
}
catch (Exception $ex) {
$order->logPaymentAttempt('Payment canceled failed -> '.$ex->getMessage(), 0, $data, $response);
}
}

/**
* @param array $data
Expand Down Expand Up @@ -230,6 +279,9 @@ protected function getPaymentFormFields($order, $data = [])
'metadata' => [
'order_id' => $order->order_id,
],
'payment_intent_data' => [
'capture_method' => $this->shouldAuthorizePayment() ? 'manual' : 'automatic',
],
];

// Share the email field in our form to Stripe checkout session,
Expand Down

0 comments on commit 76130b8

Please sign in to comment.