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 ca284d2
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions payments/StripeCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,57 @@ 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
* @param \Admin\Models\Payments_model $host
Expand Down Expand Up @@ -230,6 +281,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 ca284d2

Please sign in to comment.