From 9272589e30a4e86fb282a47daead724dfa6447ac Mon Sep 17 00:00:00 2001 From: Thomas Cross Date: Sat, 8 Mar 2025 10:51:57 -0600 Subject: [PATCH] add test and refine getUrl --- ReverePayments/ReverePayments.php | 61 ++++++++++++++++---------- test.html | 73 +++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 test.html diff --git a/ReverePayments/ReverePayments.php b/ReverePayments/ReverePayments.php index e070019..68c2fd4 100644 --- a/ReverePayments/ReverePayments.php +++ b/ReverePayments/ReverePayments.php @@ -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; diff --git a/test.html b/test.html new file mode 100644 index 0000000..24efd12 --- /dev/null +++ b/test.html @@ -0,0 +1,73 @@ + + + + + + + + + +
+

Run a Test Transaction

+ +
+ + +