From 22ae8137ac5fc3dbdacaa8d50d69e1ea2b3ec45e Mon Sep 17 00:00:00 2001 From: Enrique Barcelli Date: Sun, 18 Jul 2021 20:46:36 +0800 Subject: [PATCH] Add shopping cart to payment gateway --- README.md | 2 +- plg_hikashoppayment_triplea/triplea.php | 18 ++++++++++++++++++ plg_hikashoppayment_triplea/triplea.xml | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c6f5463..f683302 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Smart Accounts ( https://www.smt-acc.com ) Smart Accounts ( https://www.smt-acc.com ) ## More details -**This version of the code is work-in-progress and should not be use in any production site.** +**This version of the code is released for testing. Use carefully on production sites.** At this stage the plugin is able to accept payments, but cannot receive payment notifications or process refunds. The TripleA Cryptocurrency Payments API is documented here: diff --git a/plg_hikashoppayment_triplea/triplea.php b/plg_hikashoppayment_triplea/triplea.php index 854e3c3..e51bb21 100644 --- a/plg_hikashoppayment_triplea/triplea.php +++ b/plg_hikashoppayment_triplea/triplea.php @@ -26,6 +26,23 @@ class plgHikashoppaymentTriplea extends hikashopPaymentPlugin{ function onAfterOrderConfirm(&$order,&$methods,$method_id){ parent::onAfterOrderConfirm($order, $methods, $method_id); + $tacart = array(); + foreach($order->cart->products as $v) { + $temp = array(); + $temp['sku'] = $v->product_id; + $temp['label'] = $v->order_product_name; + $temp['quantity'] = (float)$v->order_product_quantity; + $temp['amount'] = ((float)$v->order_product_price+(float)$v->order_product_tax)*$temp['quantity']; + $tacart[] = $temp; + }; + $tacart = array( + "items"=>$tacart, + "shipping_cost"=>$order->order_shipping_price, //includes tax + "shipping_discount"=>$order->order_discount_price, //includes tax + "tax_cost"=>0); //tax included above + $tacart = json_encode($tacart); +// var_dump($tacart); //debug only + $payment_url = $this->payment_params->url.'/payment'; $curl = curl_init(); @@ -44,6 +61,7 @@ class plgHikashoppaymentTriplea extends hikashopPaymentPlugin{ "merchant_key": "'.$this->payment_params->merchant_key.'", "order_currency": "'.$this->currency->currency_code.'", "order_amount": '.$order->order_full_price.', + "cart": '.$tacart.', "payer_id": "'.(string)$order->order_user_id.'", "payer_name": "'.$order->cart->billing_address->address_firstname.' '.$order->cart->billing_address->address_lastname.'", "payer_email": "'.$this->user->user_email.'", diff --git a/plg_hikashoppayment_triplea/triplea.xml b/plg_hikashoppayment_triplea/triplea.xml index c365dc1..357a7c8 100644 --- a/plg_hikashoppayment_triplea/triplea.xml +++ b/plg_hikashoppayment_triplea/triplea.xml @@ -1,8 +1,8 @@ Hikashop TripleA Payment Plugin - 17 July 2021 - 1.0.1 + 18 July 2021 + 1.1.0 Enrique Barcelli e.barcelli@gmail.com http://www.smt-acc.com