From e398bccf6a1757e16469424bbbccc8c248fd6ef7 Mon Sep 17 00:00:00 2001 From: Thomas Cross Date: Tue, 4 Mar 2025 14:15:59 -0600 Subject: [PATCH] dynamically add products to revere --- ReverePayments/ReverePayments.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ReverePayments/ReverePayments.php b/ReverePayments/ReverePayments.php index 41d4558..95869b2 100644 --- a/ReverePayments/ReverePayments.php +++ b/ReverePayments/ReverePayments.php @@ -37,11 +37,10 @@ class ReverePayments extends Gateway // Ensure the product exists in Revere Payments // This will create or update the product if needed - // $this->createOrUpdateProduct($product); + $this->createOrUpdateProduct($product); // Use the generateProductSku method for consistency - // $sku = $this->generateProductSku($product); - $sku = 'abc-123'; + $sku = $this->generateProductSku($product); $lineItems[] = [ 'sku' => $sku, @@ -188,17 +187,16 @@ class ReverePayments extends Gateway // Check if product already exists $existingProduct = $this->getProductBySku($sku); - // Determine if we are adding or updating a product $action = $existingProduct ? 'update_product' : 'add_product'; // Product data to send to Revere Payments $productData = [ + 'security_key' => $apiKey, 'products' => $action, 'product_sku' => $sku, 'product_description' => $product->description ?? $product->name, 'product_cost' => $product->price, - 'product_currency' => 'USD', // Assuming USD, adjust as needed - // Add any other required product attributes here + 'product_currency' => 'USD', ]; if ($existingProduct) { @@ -226,9 +224,11 @@ class ReverePayments extends Gateway } $responseData = json_decode($response, true); + parse_str($response, $responseArray); + - if (!isset($responseData['success']) || !$responseData['success']) { - throw new Exception('Invalid response from Revere Payments API: ' . $response); + if (!isset($responseArray['response']) || $responseArray['response'] != "1") { + throw new Exception('Invalid response from Revere Payments API: ' . $responseArray); } return $responseData;