Skip to content

Commit

Permalink
Release update of Opencart V3.0 for API V4 & Dynamic IPN
Browse files Browse the repository at this point in the history
  • Loading branch information
prabalsslw committed Jun 9, 2020
1 parent 13255db commit d08cda1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 89 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ This Module Work for Opencart Version 3.x.x

### Feature

- Version 3.5 API
- IPN
- New version 4 API
- New easyCheckout Popup UI
- Dynamic IPN URL(Auto Configure)

### Installation Steps:

Expand Down Expand Up @@ -58,4 +59,4 @@ Notes :
- Team Email: integration@sslcommerz.com (For any query)
- More info: https://www.sslcommerz.com

© 2018 SSLCOMMERZ ALL RIGHTS RESERVED
© 2019 SSLCOMMERZ ALL RIGHTS RESERVED
124 changes: 73 additions & 51 deletions catalog/controller/extension/payment/SSLCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ public function index() {

if($this->config->get('payment_SSLCommerce_test')=='live') {
$data['process_url'] = $this->url->link('extension/payment/SSLCommerce/sendrequest', '', 'SSL');
$data['api_type'] = "NO";
}
else {
$data['process_url'] = $this->url->link('extension/payment/SSLCommerce/sendrequest', '', 'SSL');
$data['api_type'] = "YES";
}


Expand All @@ -108,21 +110,30 @@ public function sendrequest()
$this->load->model('checkout/order');

$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);// update order status as pending

foreach ($this->cart->getProducts() as $product) {
$products = $product['name'] . ', ';
}
$quantity=0;
foreach ($this->cart->getProducts() as $product) {
$quantity++;
}

$data['store_id'] = $this->config->get('payment_SSLCommerce_merchant');
$data['tran_id'] = $this->session->data['order_id'];
$data['total_amount'] = $_POST['total_amount'];
$data['tran_id'] = $_REQUEST['order'];
$data['total_amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);

$data['store_passwd'] = $this->config->get('payment_SSLCommerce_password');

$data['cus_name'] = $_POST['cus_name'];
$data['cus_name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'];
$data['cus_add1'] = $order_info['payment_address_1'];
$data['cus_add2'] = $order_info['payment_address_2'];
$data['cus_city'] = $order_info['payment_city'];
$data['cus_state'] = $order_info['payment_zone'];
$data['cus_postcode'] = $order_info['payment_postcode'];
$data['cus_country'] = $order_info['payment_country'];
$data['cus_phone'] = $order_info['telephone'];
$data['cus_email'] = $_POST['cus_email'];
$data['cus_email'] = $order_info['email'];
if ($this->cart->hasShipping()) {
$data['ship_name'] = $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'];
$data['ship_add1'] = $order_info['shipping_address_1'];
Expand All @@ -131,33 +142,43 @@ public function sendrequest()
$data['ship_state'] = $order_info['shipping_zone'];
$data['ship_postcode'] = $order_info['shipping_postcode'];
$data['ship_country'] = $order_info['shipping_country'];
$ship = "YES";
} else {
$data['ship_name'] = '';
$data['ship_add1'] = '';
$data['ship_add2'] = '';
$data['ship_city'] = '';
$data['ship_state'] = '';
$data['ship_postcode'] = '';
$data['ship_country'] = '';
$data['ship_name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'];
$data['ship_add1'] = $order_info['payment_address_1'];
$data['ship_add2'] = $order_info['payment_address_2'];
$data['ship_city'] = $order_info['payment_city'];
$data['ship_state'] = $order_info['payment_zone'];
$data['ship_postcode'] = $order_info['payment_postcode'];
$data['ship_country'] = $order_info['payment_country'];
$ship = "NO";
}
$data['currency'] = $_POST['currency'];
$data['currency'] = $order_info['currency_code'];
$data['success_url'] = $this->url->link('extension/payment/SSLCommerce/callback', '', 'SSL');
$data['fail_url'] = $this->url->link('extension/payment/SSLCommerce/Failed', '', 'SSL');
$data['cancel_url'] = $this->url->link('extension/payment/SSLCommerce/Cancelled', '', 'SSL');

// $data['fail_url'] = $this->url->link('checkout/failure', '', 'SSL');
// $data['cancel_url'] = $this->url->link('checkout/cart', '', 'SSL');
$data['ipn_url'] = $this->url->link('extension/payment/SSLCommerce/sslcommerz_ipn', '', 'SSL');
$data['shipping_method'] = $ship;
$data['num_of_item'] = $quantity;
$data['product_name'] = $products;
$data['product_category'] = 'Ecommerce';
$data['product_profile'] = 'general';

$security_key = $this->sslcommerz_hash_key($this->config->get('payment_SSLCommerce_password'), $data);

$data['verify_sign'] = $_POST['verify_sign'];
$data['verify_key'] = $_POST['verify_key'];
$data['verify_sign'] = $security_key['verify_sign'];
$data['verify_key'] = $security_key['verify_key'];


if($this->config->get('payment_SSLCommerce_test')=='live')
{
$redirect_url = 'https://securepay.sslcommerz.com/gwprocess/v3/api.php';
$redirect_url = 'https://securepay.sslcommerz.com/gwprocess/v4/api.php';
$api_type = "NO";
}
else
{
$redirect_url = 'https://sandbox.sslcommerz.com/gwprocess/v3/api.php';
$redirect_url = 'https://sandbox.sslcommerz.com/gwprocess/v4/api.php';
$api_type = "YES";
}

$handle = curl_init();
Expand All @@ -174,36 +195,37 @@ public function sendrequest()
{
curl_close( $handle);
$sslcommerzResponse = $content;
// print_r($sslcommerzResponse);exit;
# PARSE THE JSON RESPONSE

$sslcz = json_decode($sslcommerzResponse, true );

// print_r($sslcz);exit;

if($sslcz['status']=='SUCCESS')
{
$tran_id = $this->session->data['order_id'];
// update order status to 1 from 0.
$this->model_checkout_order->addOrderHistory($_POST['tran_id'], $this->config->get('config_order_status_id'), 'Order Initiated');
if(isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL'] != '')
{
//header("Location: " . $this->sslc_data['GatewayPageURL']);
echo "
<script>
window.location.href = '" . $sslcz['GatewayPageURL'] . "';
</script>
";
exit;
}
else
$this->model_checkout_order->addOrderHistory($tran_id, $this->config->get('config_order_status_id'), 'Order Initiated');

if(isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL']!="")
{
$this->error = "No redirect URL found!";
return $this->error;
}
if($api_type == "NO")
{
echo json_encode(['status' => 'SUCCESS', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo'] ]);

exit;
}
else if($api_type == "YES")
{
echo json_encode(['status' => 'success', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo'] ]);
exit;
}

//return json_encode(['status' => 'SUCCESS', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo'] ]);
}
}
else if($sslcz['status']=='FAILED')
{
echo "FAILED TO CONNECT WITH SSLCOMMERZ API";
echo "<br/>Status: ".$sslcz['status'];
echo "<br/>Failed Reason: ".$sslcz['failedreason'];
exit;
}
else {
echo json_encode(['status' => 'FAILED', 'data' => null, 'message' => "JSON Data parsing error!"]);
}
}
else
{
Expand Down Expand Up @@ -618,14 +640,14 @@ public function sslcommerz_ipn()
}
elseif($status == 'VALID' || $status == 'VALIDATED')
{
if($this->config->get('payment_SSLCommerce_test')=='live')
{
$valid_url_own = ("https://securepay.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json");
}
else
{
$valid_url_own = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json");
}
if($this->config->get('payment_SSLCommerce_test')=='live')
{
$valid_url_own = ("https://securepay.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json");
}
else
{
$valid_url_own = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=".$val_id."&Store_Id=".$store_id."&Store_Passwd=".$store_passwd."&v=1&format=json");
}

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $valid_url_own);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
<form action="{{ process_url}}" method="post">
<input type="hidden" name="store_id" value="{{ store_id}}" />
<input type="hidden" name="tran_id" value="{{ tran_id}}" />
<input type="hidden" name="total_amount" value="{{ total_amount }}" />
<input type="hidden" name="cus_name" value="{{ cus_name}}" />
<input type="hidden" name="cus_add1" value="{{ cus_add1}}" />
<input type="hidden" name="cus_add2" value="{{ cus_add2 }}" />
<input type="hidden" name="cus_city" value="{{ cus_city }}" />
<input type="hidden" name="cus_state" value="{{ cus_state}}" />
<input type="hidden" name="cus_postcode" value="{{ cus_postcode}}" />
<input type="hidden" name="cus_country" value="{{ cus_country}}" />
<input type="hidden" name="cus_phone" value="{{ cus_phone}}" />
<input type="hidden" name="cus_email" value="{{ cus_email }}" />
<input type="hidden" name="ship_name" value="{{ship_name}}" />
<input type="hidden" name="ship_add1" value="{{ ship_add1}}" />
<input type="hidden" name="ship_add2" value="{{ship_add2}}" />
<input type="hidden" name="ship_city" value="{{ship_city}}" />
<input type="hidden" name="ship_state" value="{{ship_state}}" />
<input type="hidden" name="ship_postcode" value="{{ship_postcode}}" />
<input type="hidden" name="ship_country" value="{{ship_country}}" />
<input type="hidden" name="currency" value="{{currency}}" />
<input type="hidden" name="success_url" value="{{success_url}}" />
<input type="hidden" name="fail_url" value="{{fail_url}}" />
<input type="hidden" name="cancel_url" value="{{cancel_url}}" />


<input type="hidden" name="value_a" value="{{detail1_text}}" />

<input type="hidden" name="verify_sign" value="{{verify_sign}}" />
<input type="hidden" name="verify_key" value="{{verify_key}}" />

<div class="buttons">
<div class="buttons">
<div class="right">
<input type="submit" value="{{button_confirm}}" class="btn btn-primary" />
<button id="sslczPayBtn" class="btn btn-primary"
token="{{ tran_id}}"
postdata=""
order="{{ tran_id}}"
endpoint="{{process_url}}">{{button_confirm}}
</button>
</div>
</div>
</form>
</div>
{% if api_type == "YES" %}
<script type="text/javascript">
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src="https://sandbox.sslcommerz.com/embed.min.js?" + Math.random().toString(36).substring(7);
s1.charset='UTF-8';
s0.parentNode.insertBefore(s1,s0);
})();
</script>
{% elseif api_type == "NO" %}
<script type="text/javascript">
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src="https://seamless-epay.sslcommerz.com/embed.min.js?" + Math.random().toString(36).substring(7);
s1.charset='UTF-8';
s0.parentNode.insertBefore(s1,s0);
})();
</script>
{% endif %}

0 comments on commit d08cda1

Please sign in to comment.