add test and refine getUrl
This commit is contained in:
parent
e8a8c804a0
commit
9272589e30
@ -33,8 +33,6 @@ class ReverePayments extends Gateway
|
||||
|
||||
$lineItems = [];
|
||||
foreach ($products as $product) {
|
||||
error_log('Product: ' . print_r($product, true));
|
||||
|
||||
// Ensure the product exists in Revere Payments
|
||||
// This will create or update the product if needed
|
||||
$this->createOrUpdateProduct($product);
|
||||
@ -48,33 +46,49 @@ class ReverePayments extends Gateway
|
||||
];
|
||||
}
|
||||
|
||||
// Create payment request
|
||||
$ch = curl_init();
|
||||
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, [
|
||||
'Content-Type: application/json'
|
||||
]);
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
$data = [
|
||||
'type' => 'sale',
|
||||
'customerVault' => [
|
||||
'addCustomer' => true
|
||||
],
|
||||
'lineItems' => $lineItems,
|
||||
'successUrl' => 'https://shilohcode.com',
|
||||
'cancelUrl' => 'https://paymenter.lasthourhosting.org/checkout',
|
||||
'receipt' => [
|
||||
'showReceipt' => true
|
||||
],
|
||||
'key' => $publicCheckoutKey,
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => 'https://secure.reverepayments.com/api/v4/cart',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => json_encode($data),
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Accept: application/json, text/plain, */*',
|
||||
'Accept-Encoding: gzip, deflate, br, zstd',
|
||||
'Accept-Language: en-US,en;q=0.9',
|
||||
'Cache-Control: no-cache',
|
||||
'Connection: keep-alive',
|
||||
'Content-Type: application/json',
|
||||
'Origin: null',
|
||||
'Pragma: no-cache',
|
||||
'Sec-Fetch-Dest: empty',
|
||||
'Sec-Fetch-Mode: cors',
|
||||
'Sec-Fetch-Site: cross-site',
|
||||
'Sec-GPC: 1',
|
||||
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
|
||||
'sec-ch-ua: "Chromium";v="134", "Not:A-Brand";v="24", "Brave";v="134"',
|
||||
'sec-ch-ua-mobile: ?0',
|
||||
'sec-ch-ua-platform: "macOS"'
|
||||
),
|
||||
));
|
||||
|
||||
// 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);
|
||||
$response = curl_exec($curl);
|
||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
|
||||
if ($httpCode < 200 || $httpCode >= 300) {
|
||||
throw new Exception('Failed to create Revere payment session: ' . $response);
|
||||
@ -87,6 +101,7 @@ class ReverePayments extends Gateway
|
||||
throw new Exception('Invalid response from Revere Payments API');
|
||||
}
|
||||
|
||||
|
||||
$redirectUrl = "https://collectcheckout.com/collect-checkout/?cartId=" . $responseData['id'];
|
||||
|
||||
return $redirectUrl;
|
||||
|
73
test.html
Normal file
73
test.html
Normal file
@ -0,0 +1,73 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
|
||||
<script
|
||||
src="https://secure.reverepayments.com/token/CollectCheckout.js"
|
||||
data-checkout-key="checkout_public_NnrZVw4gfk6B2j68MQ6u4q86PDJtH2Fn"
|
||||
></script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
width: 380px;
|
||||
padding: 20px 0 30px 0;
|
||||
margin-top: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 3px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#redirectLink {
|
||||
width: 180px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
margin: 20px auto 0 auto;
|
||||
height: 40px !important;
|
||||
font-size: 20px;
|
||||
background-color: #37805b;
|
||||
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
|
||||
transition: 200ms;
|
||||
}
|
||||
|
||||
#redirectLink:hover {
|
||||
background-color: #19c687;
|
||||
box-shadow: 0 3px 4px rgba(0, 0, 0, 0.2);
|
||||
cursor: pointer;
|
||||
transition: 200ms;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Run a Test Transaction</h1>
|
||||
<div id="redirectLink">Start</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document
|
||||
.getElementById("redirectLink")
|
||||
.addEventListener("click", function (e) {
|
||||
CollectCheckout.redirectToCheckout({
|
||||
lineItems: [
|
||||
{
|
||||
sku: "test-02",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
// successUrl: "https://shilohcode.com",
|
||||
// cancelUrl: "https://paymenter.lasthourhosting.org/checkout",
|
||||
// key: "checkout_public_NnrZVw4gfk6B2j68MQ6u4q86PDJtH2Fn",
|
||||
receipt: { showReceipt: true },
|
||||
}).then((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
Loading…
x
Reference in New Issue
Block a user