integrate with revere payment session

This commit is contained in:
Thomas Cross 2025-03-03 14:40:59 -06:00
parent 0830783d86
commit 2e174ec785

View File

@ -24,55 +24,64 @@ class ReverePayments extends Gateway
$apiKey = ExtensionHelper::getConfig('ReverePayments', 'revere_api_key');
$isTestMode = ExtensionHelper::getConfig('ReverePayments', 'revere_test_mode');
$baseUrl = $isTestMode ? 'https://api.sandbox.reverepayments.dev' : 'https://api.reverepayments.dev';
// TODO: find out what the sandbox url is
$baseRevereApiUrl = $isTestMode ? 'https://api.sandbox.reverepayments.dev' : 'https://api.reverepayments.dev';
$baseCartUrl = $isTestMode ? 'https://secure.reverepayments.com' : 'https://secure.reverepayments.com';
// Create line items array
$items = [];
// Create line items array for Collect Checkout
$lineItems = [];
foreach ($products as $product) {
$items[] = [
'name' => $product->name,
'amount' => $product->price * 100, // Convert to cents
'quantity' => $product->quantity
$lineItems[] = [
'sku' => $product->id,
// 'name' => $product->name,
// 'description' => $product->description ?? $product->name,
'quantity' => $product->quantity,
// 'price' => $product->price
];
}
// Create payment session
// Create payment request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/payment-sessions');
curl_setopt($ch, CURLOPT_URL, $baseCartUrl . '/api/v4/cart');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
$data = [
'amount' => $total * 100, // Convert to cents
'currency' => ExtensionHelper::getCurrency(),
'line_items' => $items,
'success_url' => route('clients.invoice.show', $orderId),
'cancel_url' => route('clients.invoice.show', $orderId),
'metadata' => [
'order_id' => $orderId,
'user_id' => auth()->user()->id
'type' => 'sale',
'customerVault' => [
'addCustomer' => true
],
'customer' => [
'email' => auth()->user()->email
]
'lineItems' => $lineItems,
'successUrl' => route('clients.invoice.show', $orderId),
'cancelUrl' => route('clients.invoice.show', $orderId),
'key' => $apiKey,
];
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curlHandle, CURLOPT_VERBOSE, true);
// Enable verbose output for debugging
curl_setopt($ch, CURLOPT_VERBOSE, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception('Failed to create Revere payment session');
if ($httpCode < 200 || $httpCode >= 300) {
throw new Exception('Failed to create Revere payment session: ' . $response);
}
return json_decode($response);
$responseData = json_decode($response, true);
if (!isset($responseData['url'])) {
throw new Exception('Invalid response from Revere Payments API');
}
return $responseData['url'];
}
public function webhook(Request $request)
@ -100,8 +109,7 @@ class ReverePayments extends Gateway
public function pay($total, $products, $orderId)
{
$session = $this->getUrl($total, $products, $orderId);
return $session->checkout_url;
return $this->getUrl($total, $products, $orderId);
}
public function getConfig()
@ -111,7 +119,7 @@ class ReverePayments extends Gateway
'name' => 'revere_api_key',
'friendlyName' => 'Revere API Key',
'type' => 'text',
'description' => 'Your Revere Payments API key',
'description' => 'Your Revere Payments Checkout Public Key (starts with checkout_public_)',
'required' => true,
],
[