├── .gitignore ├── OrderTransaction.php ├── README.md ├── checkout_ajax.php ├── checkout_hosted.php ├── config └── config.php ├── db_connection.php ├── example_easycheckout.php ├── example_hosted.php ├── lib ├── AbstractSslCommerz.php ├── SslCommerzInterface.php └── SslCommerzNotification.php ├── orders.sql └── pg_redirection ├── cancel.php ├── fail.php ├── ipn.php └── success.php /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | -------------------------------------------------------------------------------- /OrderTransaction.php: -------------------------------------------------------------------------------- 1 | Pay Now 44 | 45 | 46 | ``` 47 | 48 | * __Step 6:__ Use the below script before the end of body tag. 49 | 50 | ##### For Sandbox 51 | ``` 52 | 63 | 64 | ``` 65 | ##### For Live 66 | ``` 67 | 78 | 79 | ``` 80 | 81 | 82 | * __Step 7:__ For redirecting action from SSLCommerz Payment gateway, we have also provided sample `success.php`, `cancel.php`, `fail.php` and `ipn.php` files. You can update those files according to your need. 83 | 84 | ### Contributors 85 | 86 | >Prabal Mallick 87 | 88 | > Md. Rakibul Islam 89 | 90 | > integration@sslcommerz.com -------------------------------------------------------------------------------- /checkout_ajax.php: -------------------------------------------------------------------------------- 1 | "REF0001", "product" => "DHK TO BRS AC A1", "quantity" => "1", "amount" => "200.00"), 61 | // array("sku" => "REF0002", "product" => "DHK TO BRS AC A2", "quantity" => "1", "amount" => "200.00"), 62 | // array("sku" => "REF0003", "product" => "DHK TO BRS AC A3", "quantity" => "1", "amount" => "200.00"), 63 | // array("sku" => "REF0004", "product" => "DHK TO BRS AC A4", "quantity" => "2", "amount" => "200.00") 64 | // )); 65 | 66 | //$post_data['emi_max_inst_option'] = "9"; 67 | //$post_data['emi_selected_inst'] = "24"; 68 | 69 | 70 | //$post_data['product_amount'] = "0"; 71 | //$post_data['discount_amount'] = "5"; 72 | 73 | //$post_data['product_amount'] = "100"; 74 | //$post_data['vat'] = "5"; 75 | //$post_data['discount_amount'] = "5"; 76 | //$post_data['convenience_fee'] = "3"; 77 | 78 | //$post_data['discount_amount'] = "5"; 79 | 80 | //$post_data['multi_card_name'] = "brac_visa,brac_master"; 81 | //$post_data['allowed_bin'] = "408860,458763,489035,432147,432145,548895,545610,545538,432149,484096,484097,464573,539932,436475"; 82 | 83 | # RECURRING DATA 84 | // $schedule = array( 85 | // "refer" => "5B90BA91AA3F2", # Subscriber id which generated in Merchant Admin panel 86 | // "acct_no" => "01730671731", 87 | // "type" => "daily", # Recurring Schedule - monthly,weekly,daily 88 | // //"dayofmonth" => "24", # 1st day of every month 89 | // //"month" => "8", # 1st day of January for Yearly Recurring 90 | // //"week" => "sat", # In case, weekly recurring 91 | 92 | // ); 93 | 94 | 95 | // $post_data["product_shipping_contry"] = "Bangladesh"; 96 | // $post_data["vip_customer"] = "YES"; 97 | // $post_data["hours_till_departure"] = "12 hrs"; 98 | // $post_data["flight_type"] = "Oneway"; 99 | // $post_data["journey_from_to"] = "DAC-CGP"; 100 | // $post_data["third_party_booking"] = "No"; 101 | 102 | // $post_data["hotel_name"] = "Sheraton"; 103 | // $post_data["length_of_stay"] = "2 days"; 104 | // $post_data["check_in_time"] = "24 hrs"; 105 | // $post_data["hotel_city"] = "Dhaka"; 106 | 107 | 108 | // $post_data["product_type"] = "Prepaid"; 109 | // $post_data["phone_number"] = "01711111111"; 110 | // $post_data["country_topUp"] = "Bangladesh"; 111 | 112 | // $post_data["shipToFirstName"] = "John"; 113 | // $post_data["shipToLastName"] = "Doe"; 114 | // $post_data["shipToStreet"] = "93 B, New Eskaton Road"; 115 | // $post_data["shipToCity"] = "Dhaka"; 116 | // $post_data["shipToState"] = "Dhaka"; 117 | // $post_data["shipToPostalCode"] = "1000"; 118 | // $post_data["shipToCountry"] = "Bangladesh"; 119 | // $post_data["shipToEmail"] = "john.doe@email.com"; 120 | // $post_data["ship_to_phone_number"] = "01711111111"; 121 | 122 | # SPECIAL PARAM 123 | // $post_data['tokenize_id'] = "1"; 124 | 125 | # 1 : Physical Goods 126 | # 2 : Non-Physical Goods Vertical(software) 127 | # 3 : Airline Vertical Profile 128 | # 4 : Travel Vertical Profile 129 | # 5 : Telecom Vertical Profile 130 | 131 | // $post_data["product_profile_id"] = "5"; 132 | 133 | // $post_data["topup_number"] = "01711111111"; # topUpNumber 134 | 135 | # First, save the input data into local database table `orders` 136 | $query = new OrderTransaction(); 137 | $sql = $query->saveTransactionQuery($post_data); 138 | 139 | if ($conn_integration->query($sql) === TRUE) { 140 | 141 | # Call the Payment Gateway Library 142 | $sslcz = new SslCommerzNotification(); 143 | $sslcz->makePayment($post_data, 'checkout', 'plain'); 144 | } else { 145 | echo "Error: " . $sql . "
" . $conn_integration->error; 146 | } 147 | -------------------------------------------------------------------------------- /checkout_hosted.php: -------------------------------------------------------------------------------- 1 | "REF0001", "product" => "DHK TO BRS AC A1", "quantity" => "1", "amount" => "200.00"), 65 | // array("sku" => "REF0002", "product" => "DHK TO BRS AC A2", "quantity" => "1", "amount" => "200.00"), 66 | // array("sku" => "REF0003", "product" => "DHK TO BRS AC A3", "quantity" => "1", "amount" => "200.00"), 67 | // array("sku" => "REF0004", "product" => "DHK TO BRS AC A4", "quantity" => "2", "amount" => "200.00") 68 | // )); 69 | 70 | //$post_data['emi_max_inst_option'] = "9"; 71 | //$post_data['emi_selected_inst'] = "24"; 72 | 73 | 74 | //$post_data['product_amount'] = "0"; 75 | //$post_data['discount_amount'] = "5"; 76 | /* 77 | $post_data['product_amount'] = "100"; 78 | $post_data['vat'] = "5"; 79 | $post_data['discount_amount'] = "5"; 80 | $post_data['convenience_fee'] = "3"; 81 | */ 82 | //$post_data['discount_amount'] = "5"; 83 | 84 | //$post_data['multi_card_name'] = "brac_visa,brac_master"; 85 | //$post_data['allowed_bin'] = "408860,458763,489035,432147,432145,548895,545610,545538,432149,484096,484097,464573,539932,436475"; 86 | 87 | # RECURRING DATA 88 | // $schedule = array( 89 | // "refer" => "5B90BA91AA3F2", # Subscriber id which generated in Merchant Admin panel 90 | // "acct_no" => "01730671731", 91 | // "type" => "daily", # Recurring Schedule - monthly,weekly,daily 92 | // //"dayofmonth" => "24", # 1st day of every month 93 | // //"month" => "8", # 1st day of January for Yearly Recurring 94 | // //"week" => "sat", # In case, weekly recurring 95 | 96 | // ); 97 | 98 | 99 | // $post_data["product_shipping_contry"] = "Bangladesh"; 100 | // $post_data["vip_customer"] = "YES"; 101 | // $post_data["hours_till_departure"] = "12 hrs"; 102 | // $post_data["flight_type"] = "Oneway"; 103 | // $post_data["journey_from_to"] = "DAC-CGP"; 104 | // $post_data["third_party_booking"] = "No"; 105 | 106 | // $post_data["hotel_name"] = "Sheraton"; 107 | // $post_data["length_of_stay"] = "2 days"; 108 | // $post_data["check_in_time"] = "24 hrs"; 109 | // $post_data["hotel_city"] = "Dhaka"; 110 | 111 | 112 | // $post_data["product_type"] = "Prepaid"; 113 | // $post_data["phone_number"] = "01711111111"; 114 | // $post_data["country_topUp"] = "Bangladesh"; 115 | 116 | // $post_data["shipToFirstName"] = "John"; 117 | // $post_data["shipToLastName"] = "Doe"; 118 | // $post_data["shipToStreet"] = "93 B, New Eskaton Road"; 119 | // $post_data["shipToCity"] = "Dhaka"; 120 | // $post_data["shipToState"] = "Dhaka"; 121 | // $post_data["shipToPostalCode"] = "1000"; 122 | // $post_data["shipToCountry"] = "Bangladesh"; 123 | // $post_data["shipToEmail"] = "john.doe@email.com"; 124 | // $post_data["ship_to_phone_number"] = "01711111111"; 125 | 126 | # SPECIAL PARAM 127 | // $post_data['tokenize_id'] = "1"; 128 | 129 | # 1 : Physical Goods 130 | # 2 : Non-Physical Goods Vertical(software) 131 | # 3 : Airline Vertical Profile 132 | # 4 : Travel Vertical Profile 133 | # 5 : Telecom Vertical Profile 134 | 135 | // $post_data["product_profile_id"] = "5"; 136 | 137 | // $post_data["topup_number"] = "01711111111"; # topUpNumber 138 | 139 | # First, save the input data into local database table `orders` 140 | $query = new OrderTransaction(); 141 | $sql = $query->saveTransactionQuery($post_data); 142 | 143 | if ($conn_integration->query($sql) === TRUE) { 144 | 145 | # Call the Payment Gateway Library 146 | $sslcz = new SslCommerzNotification(); 147 | $msg = $sslcz->makePayment($post_data, 'hosted'); 148 | if (!is_array($msg)) { 149 | echo $msg; 150 | } 151 | } else { 152 | echo "Error: " . $sql . "
" . $conn_integration->error; 153 | } 154 | 155 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | 'pg_redirection/success.php', // your success url 21 | 'failed_url' => 'pg_redirection/fail.php', // your fail url 22 | 'cancel_url' => 'pg_redirection/cancel.php', //your cancel url 23 | 'ipn_url' => 'pg_redirection/ipn.php', // your ipn url 24 | 25 | 26 | 'projectPath' => PROJECT_PATH, 27 | 'apiDomain' => IS_SANDBOX ? 'https://sandbox.sslcommerz.com' : 'https://securepay.sslcommerz.com', 28 | 'apiCredentials' => [ 29 | 'store_id' => STORE_ID, 30 | 'store_password' => STORE_PASSWORD, 31 | ], 32 | 'apiUrl' => [ 33 | 'make_payment' => "/gwprocess/v4/api.php", 34 | 'order_validate' => "/validator/api/validationserverAPI.php", 35 | ], 36 | 'connect_from_localhost' => false, 37 | 'verify_hash' => true, 38 | ]; 39 | -------------------------------------------------------------------------------- /db_connection.php: -------------------------------------------------------------------------------- 1 | "; // Put the MySQL Username 5 | $password = ""; // Put the MySQL Password 6 | $database = ""; // Put the Database Name 7 | 8 | // Create connection for integration 9 | $conn_integration = mysqli_connect($servername, $username, $password, $database); 10 | 11 | // Check connection for integration 12 | if (!$conn_integration) { 13 | die("Connection failed: " . mysqli_connect_error()); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /example_easycheckout.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Example - EasyCheckout (Popup) | SSLCommerz 9 | 10 | 11 | 13 | 14 | 30 | 31 | 32 |
33 |
34 |

EasyCheckout (Popup) - SSLCommerz

35 | 36 |

This is a dummy checkout page, and NOT meant for production use.

37 |
38 | 39 |
40 |
41 |

42 | Your cart 43 | 3 44 |

45 |
    46 |
  • 47 |
    48 |
    Product name
    49 | Brief description 50 |
    51 | 1000 52 |
  • 53 |
  • 54 |
    55 |
    Second product
    56 | Brief description 57 |
    58 | 50 59 |
  • 60 |
  • 61 |
    62 |
    Third item
    63 | Brief description 64 |
    65 | 150 66 |
  • 67 |
  • 68 | Total (BDT) 69 | 1200 TK 70 |
  • 71 |
72 |
73 |
74 |

Billing address

75 |
76 |
77 | 78 | 80 |
81 | Valid customer name is required. 82 |
83 |
84 |
85 | 86 |
87 | 88 |
89 |
90 | +88 91 |
92 | 94 |
95 | Your Mobile number is required. 96 |
97 |
98 |
99 | 100 |
101 | 102 | 104 |
105 | Please enter a valid email address for shipping updates. 106 |
107 |
108 | 109 |
110 | 111 | 113 |
114 | Please enter your shipping address. 115 |
116 |
117 | 118 |
119 | 120 | 121 |
122 | 123 |
124 |
125 | 126 | 130 |
131 | Please select a valid country. 132 |
133 |
134 |
135 | 136 | 140 |
141 | Please provide a valid state. 142 |
143 |
144 |
145 | 146 | 147 |
148 | Zip code required. 149 |
150 |
151 |
152 |
153 |
154 | 155 | 156 | 158 |
159 |
160 | 161 | 162 |
163 |
164 | 170 |
171 |
172 | 173 | 181 |
182 | 185 | 188 | 191 | 192 | 193 | 194 | 215 | 216 | -------------------------------------------------------------------------------- /example_hosted.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Example - Hosted Checkout | SSLCommerz 9 | 10 | 11 | 13 | 14 | 30 | 31 | 32 |
33 |
34 |

Hosted Payment - SSLCommerz

35 |

This is a dummy checkout page, and NOT meant for production use.

36 |
37 | 38 |
39 |
40 |

41 | Your cart 42 | 3 43 |

44 |
    45 |
  • 46 |
    47 |
    Product name
    48 | Brief description 49 |
    50 | 1000 51 |
  • 52 |
  • 53 |
    54 |
    Second product
    55 | Brief description 56 |
    57 | 50 58 |
  • 59 |
  • 60 |
    61 |
    Third item
    62 | Brief description 63 |
    64 | 150 65 |
  • 66 |
  • 67 | Total (BDT) 68 | 1200 TK 69 |
  • 70 |
71 |
72 |
73 |

Billing address

74 |
75 |
76 |
77 | 78 | 80 |
81 | Valid customer name is required. 82 |
83 |
84 |
85 | 86 |
87 | 88 |
89 |
90 | +88 91 |
92 | 94 |
95 | Your Mobile number is required. 96 |
97 |
98 |
99 | 100 |
101 | 102 | 104 |
105 | Please enter a valid email address for shipping updates. 106 |
107 |
108 | 109 |
110 | 111 | 113 |
114 | Please enter your shipping address. 115 |
116 |
117 | 118 |
119 | 120 | 121 |
122 | 123 |
124 |
125 | 126 | 130 |
131 | Please select a valid country. 132 |
133 |
134 |
135 | 136 | 140 |
141 | Please provide a valid state. 142 |
143 |
144 |
145 | 146 | 147 |
148 | Zip code required. 149 |
150 |
151 |
152 |
153 |
154 | 155 | 156 | 158 |
159 |
160 | 161 | 162 |
163 |
164 | 165 |
166 |
167 |
168 | 169 | 177 |
178 | 181 | 184 | 187 | 188 | -------------------------------------------------------------------------------- /lib/AbstractSslCommerz.php: -------------------------------------------------------------------------------- 1 | storeId = $storeID; 15 | } 16 | 17 | protected function getStoreId() 18 | { 19 | return $this->storeId; 20 | } 21 | 22 | protected function setStorePassword($storePassword) 23 | { 24 | $this->storePassword = $storePassword; 25 | } 26 | 27 | protected function getStorePassword() 28 | { 29 | return $this->storePassword; 30 | } 31 | 32 | protected function setApiUrl($url) 33 | { 34 | $this->apiUrl = $url; 35 | } 36 | 37 | protected function getApiUrl() 38 | { 39 | return $this->apiUrl; 40 | } 41 | 42 | /** 43 | * @param $data 44 | * @param array $header 45 | * @param bool $setLocalhost 46 | * @return bool|string 47 | */ 48 | public function callToApi($data, $header = [], $setLocalhost = false) 49 | { 50 | $curl = curl_init(); 51 | 52 | if (!$setLocalhost) { 53 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); 54 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // The default value for this option is 2. It means, it has to have the same name in the certificate as is in the URL you operate against. 55 | } else { 56 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 57 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // When the verify value is 0, the connection succeeds regardless of the names in the certificate. 58 | } 59 | 60 | curl_setopt($curl, CURLOPT_URL, $this->getApiUrl()); 61 | curl_setopt($curl, CURLOPT_HEADER, 0); 62 | curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 63 | curl_setopt($curl, CURLOPT_TIMEOUT, 60); 64 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 65 | 66 | curl_setopt($curl, CURLOPT_POST, 1); 67 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 68 | 69 | $response = curl_exec($curl); 70 | $err = curl_error($curl); 71 | $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 72 | $curlErrorNo = curl_errno($curl); 73 | curl_close($curl); 74 | 75 | if ($code == 200 & !($curlErrorNo)) { 76 | return $response; 77 | } else { 78 | return "FAILED TO CONNECT WITH SSLCOMMERZ API"; 79 | //return "cURL Error #:" . $err; 80 | } 81 | } 82 | 83 | /** 84 | * @param $response 85 | * @param string $type 86 | * @param string $pattern 87 | * @return false|mixed|string 88 | */ 89 | public function formatResponse($response, $type = 'checkout', $pattern = 'json') 90 | { 91 | $sslcz = json_decode($response, true); 92 | 93 | if ($type != 'checkout') { 94 | return $sslcz; 95 | } else { 96 | if (isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL'] != "") { 97 | // this is important to show the popup, return or echo to send json response back 98 | $response = json_encode(['status' => 'success', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo']]); 99 | } else { 100 | if (strpos($sslcz['failedreason'],'Store Credential') === false) { 101 | $message = $sslcz['failedreason']; 102 | } else { 103 | $message = "Check the IS_SANDBOX, STORE_ID and STORE_PASSWORD value in config.php; DO NOT USE MERCHANT PANEL PASSWORD HERE."; 104 | } 105 | $response = json_encode(['status' => 'fail', 'data' => null, 'message' => $message]); 106 | } 107 | 108 | if ($pattern == 'json') { 109 | return $response; 110 | } else { 111 | echo $response; 112 | } 113 | } 114 | } 115 | 116 | /** 117 | * @param $url 118 | * @param bool $permanent 119 | */ 120 | public function redirect($url, $permanent = false) 121 | { 122 | header('Location: ' . $url, true, $permanent ? 301 : 302); 123 | 124 | exit(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /lib/SslCommerzInterface.php: -------------------------------------------------------------------------------- 1 | config = include(__DIR__ . '/../config/config.php'); 29 | 30 | $this->setStoreId($this->config['apiCredentials']['store_id']); 31 | $this->setStorePassword($this->config['apiCredentials']['store_password']); 32 | } 33 | 34 | public function orderValidate($post_data, $trx_id = '', $amount = 0, $currency = "BDT") 35 | { 36 | if ($post_data == '' && $trx_id == '' && !is_array($post_data)) { 37 | $this->error = "Please provide valid transaction ID and post request data"; 38 | return $this->error; 39 | } 40 | 41 | $validation = $this->validate($trx_id, $amount, $currency, $post_data); 42 | 43 | if ($validation) { 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } 49 | 50 | 51 | # VALIDATE SSLCOMMERZ TRANSACTION 52 | protected function validate($merchant_trans_id, $merchant_trans_amount, $merchant_trans_currency, $post_data) 53 | { 54 | 55 | # MERCHANT SYSTEM INFO 56 | if ($merchant_trans_id != "" && $merchant_trans_amount != 0) { 57 | 58 | # CALL THE FUNCTION TO CHECK THE RESUKT 59 | $post_data['store_id'] = $this->getStoreId(); 60 | $post_data['store_pass'] = $this->getStorePassword(); 61 | 62 | if ($this->SSLCOMMERZ_hash_verify($post_data, $this->getStorePassword())) { 63 | 64 | $val_id = urlencode($post_data['val_id']); 65 | $store_id = urlencode($this->getStoreId()); 66 | $store_passwd = urlencode($this->getStorePassword()); 67 | $requested_url = ($this->config['apiDomain'] . $this->config['apiUrl']['order_validate'] . "?val_id=" . $val_id . "&store_id=" . $store_id . "&store_passwd=" . $store_passwd . "&v=1&format=json"); 68 | 69 | $handle = curl_init(); 70 | curl_setopt($handle, CURLOPT_URL, $requested_url); 71 | curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); 72 | 73 | if ($this->config['connect_from_localhost']) { 74 | curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0); 75 | curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0); 76 | } else { 77 | curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2); 78 | curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1); 79 | } 80 | 81 | 82 | $result = curl_exec($handle); 83 | 84 | $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); 85 | 86 | if ($code == 200 && !(curl_errno($handle))) { 87 | 88 | # TO CONVERT AS ARRAY 89 | # $result = json_decode($result, true); 90 | # $status = $result['status']; 91 | 92 | # TO CONVERT AS OBJECT 93 | $result = json_decode($result); 94 | $this->sslc_data = $result; 95 | 96 | # TRANSACTION INFO 97 | $status = $result->status; 98 | $tran_date = $result->tran_date; 99 | $tran_id = $result->tran_id; 100 | $val_id = $result->val_id; 101 | $amount = $result->amount; 102 | $store_amount = $result->store_amount; 103 | $bank_tran_id = $result->bank_tran_id; 104 | $card_type = $result->card_type; 105 | $currency_type = $result->currency_type; 106 | $currency_amount = $result->currency_amount; 107 | 108 | # ISSUER INFO 109 | $card_no = $result->card_no; 110 | $card_issuer = $result->card_issuer; 111 | $card_brand = $result->card_brand; 112 | $card_issuer_country = $result->card_issuer_country; 113 | $card_issuer_country_code = $result->card_issuer_country_code; 114 | 115 | # API AUTHENTICATION 116 | $APIConnect = $result->APIConnect; 117 | $validated_on = $result->validated_on; 118 | $gw_version = $result->gw_version; 119 | 120 | # GIVE SERVICE 121 | if ($status == "VALID" || $status == "VALIDATED") { 122 | if ($merchant_trans_currency == "BDT") { 123 | if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $amount) < 1) && trim($merchant_trans_currency) == trim('BDT')) { 124 | return true; 125 | } else { 126 | # DATA TEMPERED 127 | $this->error = "Data has been tempered"; 128 | return false; 129 | } 130 | } else { 131 | //echo "trim($merchant_trans_id) == trim($tran_id) && ( abs($merchant_trans_amount-$currency_amount) < 1 ) && trim($merchant_trans_currency)==trim($currency_type)"; 132 | if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $currency_amount) < 1) && trim($merchant_trans_currency) == trim($currency_type)) { 133 | return true; 134 | } else { 135 | # DATA TEMPERED 136 | $this->error = "Data has been tempered"; 137 | return false; 138 | } 139 | } 140 | } else { 141 | # FAILED TRANSACTION 142 | $this->error = "Failed Transaction"; 143 | return false; 144 | } 145 | } else { 146 | # Failed to connect with SSLCOMMERZ 147 | $this->error = "Faile to connect with SSLCOMMERZ"; 148 | return false; 149 | } 150 | } else { 151 | # Hash validation failed 152 | $this->error = "Hash validation failed"; 153 | return false; 154 | } 155 | } else { 156 | # INVALID DATA 157 | $this->error = "Invalid data"; 158 | return false; 159 | } 160 | } 161 | 162 | # FUNCTION TO CHECK HASH VALUE 163 | protected function SSLCOMMERZ_hash_verify($post_data, $store_passwd = "") 164 | { 165 | if (!$this->config['verify_hash']) { 166 | return true; 167 | } 168 | 169 | if (isset($post_data) && isset($post_data['verify_sign']) && isset($post_data['verify_key'])) { 170 | # NEW ARRAY DECLARED TO TAKE VALUE OF ALL POST 171 | $pre_define_key = explode(',', $post_data['verify_key']); 172 | 173 | $new_data = array(); 174 | if (!empty($pre_define_key)) { 175 | foreach ($pre_define_key as $value) { 176 | if (isset($post_data[$value])) { 177 | $new_data[$value] = ($post_data[$value]); 178 | } 179 | } 180 | } 181 | # ADD MD5 OF STORE PASSWORD 182 | $new_data['store_passwd'] = md5($store_passwd); 183 | 184 | # SORT THE KEY AS BEFORE 185 | ksort($new_data); 186 | 187 | $hash_string = ""; 188 | foreach ($new_data as $key => $value) { 189 | $hash_string .= $key . '=' . ($value) . '&'; 190 | } 191 | $hash_string = rtrim($hash_string, '&'); 192 | 193 | if (md5($hash_string) == $post_data['verify_sign']) { 194 | 195 | return true; 196 | } else { 197 | $this->error = "Verification signature not matched"; 198 | return false; 199 | } 200 | } else { 201 | $this->error = 'Required data mission. ex: verify_key, verify_sign'; 202 | return false; 203 | } 204 | } 205 | 206 | /** 207 | * @param array $requestData 208 | * @param string $type 209 | * @param string $pattern 210 | * @return false|mixed|string 211 | */ 212 | public function makePayment(array $requestData, $type = 'checkout', $pattern = 'json') 213 | { 214 | if (empty($requestData)) { 215 | return "Please provide a valid information list about transaction with transaction id, amount, success url, fail url, cancel url, store id and pass at least"; 216 | } 217 | 218 | $header = []; 219 | 220 | $this->setApiUrl($this->config['apiDomain'] . $this->config['apiUrl']['make_payment']); 221 | 222 | // Set the required/additional params 223 | $this->setParams($requestData); 224 | 225 | // Set the authentication information 226 | $this->setAuthenticationInfo(); 227 | 228 | // Now, call the Gateway API 229 | $response = $this->callToApi($this->data, $header, $this->config['connect_from_localhost']); 230 | 231 | $formattedResponse = $this->formatResponse($response, $type, $pattern); // Here we will define the response pattern 232 | 233 | if ($type == 'hosted') { 234 | if (!empty($formattedResponse['GatewayPageURL'])) { 235 | $this->redirect($formattedResponse['GatewayPageURL']); 236 | } else { 237 | return $formattedResponse['failedreason']; 238 | } 239 | } else { 240 | return $formattedResponse; 241 | } 242 | } 243 | 244 | 245 | protected function setSuccessUrl() 246 | { 247 | $this->successUrl = $this->config['projectPath'] . '/' . $this->config['success_url']; 248 | } 249 | 250 | protected function getSuccessUrl() 251 | { 252 | return $this->successUrl; 253 | } 254 | 255 | protected function setFailedUrl() 256 | { 257 | $this->failedUrl = $this->config['projectPath'] . '/' . $this->config['failed_url']; 258 | } 259 | 260 | protected function getFailedUrl() 261 | { 262 | return $this->failedUrl; 263 | } 264 | 265 | protected function setCancelUrl() 266 | { 267 | $this->cancelUrl = $this->config['projectPath'] . '/' . $this->config['cancel_url']; 268 | } 269 | 270 | protected function getCancelUrl() 271 | { 272 | return $this->cancelUrl; 273 | } 274 | 275 | protected function setIpnUrl() 276 | { 277 | $this->ipnUrl = $this->config['projectPath'] . '/' . $this->config['ipn_url']; 278 | } 279 | 280 | protected function getIpnUrl() 281 | { 282 | return $this->ipnUrl; 283 | } 284 | 285 | public function setParams($requestData) 286 | { 287 | ## Integration Required Parameters 288 | $this->setRequiredInfo($requestData); 289 | 290 | ## Customer Information 291 | $this->setCustomerInfo($requestData); 292 | 293 | ## Shipment Information 294 | $this->setShipmentInfo($requestData); 295 | 296 | ## Product Information 297 | $this->setProductInfo($requestData); 298 | 299 | ## Customized or Additional Parameters 300 | $this->setAdditionalInfo($requestData); 301 | } 302 | 303 | public function setAuthenticationInfo() 304 | { 305 | $this->data['store_id'] = $this->getStoreId(); 306 | $this->data['store_passwd'] = $this->getStorePassword(); 307 | 308 | return $this->data; 309 | } 310 | 311 | public function setRequiredInfo(array $info) 312 | { 313 | $this->data['total_amount'] = $info['total_amount']; // decimal (10,2) Mandatory - The amount which will process by SSLCommerz. It shall be decimal value (10,2). Example : 55.40. The transaction amount must be from 10.00 BDT to 500000.00 BDT 314 | $this->data['currency'] = $info['currency']; // string (3) Mandatory - The currency type must be mentioned. It shall be three characters. Example : BDT, USD, EUR, SGD, INR, MYR, etc. If the transaction currency is not BDT, then it will be converted to BDT based on the current convert rate. Example : 1 USD = 82.22 BDT. 315 | $this->data['tran_id'] = $info['tran_id']; // string (30) Mandatory - Unique transaction ID to identify your order in both your end and SSLCommerz 316 | $this->data['product_category'] = $info['product_category']; // string (50) Mandatory - Mention the product category. It is a open field. Example - clothing,shoes,watches,gift,healthcare, jewellery,top up,toys,baby care,pants,laptop,donation,etc 317 | 318 | // Set the SUCCESS, FAIL, CANCEL and IPN URL before setting the other parameters 319 | $this->setSuccessUrl(); 320 | $this->setFailedUrl(); 321 | $this->setCancelUrl(); 322 | $this->setIpnUrl(); 323 | 324 | $this->data['success_url'] = $this->getSuccessUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect after successful payment (Length: 255) 325 | $this->data['fail_url'] = $this->getFailedUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect after any failure occure during payment (Length: 255) 326 | $this->data['cancel_url'] = $this->getCancelUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect if user canceled the transaction (Length: 255) 327 | 328 | /* 329 | * IPN is very important feature to integrate with your site(s). 330 | * Some transaction could be pending or customer lost his/her session, in such cases back-end IPN plays a very important role to update your backend office. 331 | * 332 | * Type: string (255) 333 | * Important! Not mandatory, however better to use to avoid missing any payment notification - It is the Instant Payment Notification (IPN) URL of your website where SSLCOMMERZ will send the transaction's status (Length: 255). 334 | * The data will be communicated as SSLCOMMERZ Server to your Server. So, customer session will not work. 335 | * */ 336 | $this->data['ipn_url'] = $this->getIpnUrl(); 337 | 338 | /* 339 | * Type: string (30) 340 | * Do not Use! If you do not customize the gateway list - You can control to display the gateway list at SSLCommerz gateway selection page by providing this parameters. 341 | * Multi Card: 342 | brac_visa = BRAC VISA 343 | dbbl_visa = Dutch Bangla VISA 344 | city_visa = City Bank Visa 345 | ebl_visa = EBL Visa 346 | sbl_visa = Southeast Bank Visa 347 | brac_master = BRAC MASTER 348 | dbbl_master = MASTER Dutch-Bangla 349 | city_master = City Master Card 350 | ebl_master = EBL Master Card 351 | sbl_master = Southeast Bank Master Card 352 | city_amex = City Bank AMEX 353 | qcash = QCash 354 | dbbl_nexus = DBBL Nexus 355 | bankasia = Bank Asia IB 356 | abbank = AB Bank IB 357 | ibbl = IBBL IB and Mobile Banking 358 | mtbl = Mutual Trust Bank IB 359 | bkash = Bkash Mobile Banking 360 | dbblmobilebanking = DBBL Mobile Banking 361 | city = City Touch IB 362 | upay = Upay 363 | tapnpay = Tap N Pay Gateway 364 | * GROUP GATEWAY 365 | internetbank = For all internet banking 366 | mobilebank = For all mobile banking 367 | othercard = For all cards except visa,master and amex 368 | visacard = For all visa 369 | mastercard = For All Master card 370 | amexcard = For Amex Card 371 | * */ 372 | $this->data['multi_card_name'] = (isset($info['multi_card_name'])) ? $info['multi_card_name'] : null; 373 | 374 | /* 375 | * Type: string (255) 376 | * Do not Use! If you do not control on transaction - You can provide the BIN of card to allow the transaction must be completed by this BIN. You can declare by coma ',' separate of these BIN. 377 | * Example: 371598,371599,376947,376948,376949 378 | * */ 379 | $this->data['allowed_bin'] = (isset($info['allowed_bin'])) ? $info['allowed_bin'] : null; 380 | 381 | ## Parameters to Handle EMI Transaction ## 382 | $this->data['emi_option'] = (isset($info['emi_option'])) ? $info['emi_option'] : null; // integer (1) Mandatory - This is mandatory if transaction is EMI enabled and Value must be 1/0. Here, 1 means customer will get EMI facility for this transaction 383 | $this->data['emi_max_inst_option'] = (isset($info['emi_max_inst_option'])) ? $info['emi_max_inst_option'] : null; // integer (2) Max instalment Option, Here customer will get 3,6, 9 instalment at gateway page 384 | $this->data['emi_selected_inst'] = (isset($info['emi_selected_inst'])) ? $info['emi_selected_inst'] : null; // integer (2) Customer has selected from your Site, So no instalment option will be displayed at gateway page 385 | 386 | return $this->data; 387 | } 388 | 389 | public function setCustomerInfo(array $info) 390 | { 391 | $this->data['cus_name'] = $info['cus_name']; // string (50) Mandatory - Your customer name to address the customer in payment receipt email 392 | $this->data['cus_email'] = $info['cus_email']; // string (50) Mandatory - Valid email address of your customer to send payment receipt from SSLCommerz end 393 | $this->data['cus_add1'] = $info['cus_add1']; // string (50) Mandatory - Address of your customer. Not mandatory but useful if provided 394 | $this->data['cus_add2'] = $info['cus_add2']; // string (50) Address line 2 of your customer. Not mandatory but useful if provided 395 | $this->data['cus_city'] = $info['cus_city']; // string (50) Mandatory - City of your customer. Not mandatory but useful if provided 396 | $this->data['cus_state'] = (isset($info['cus_state'])) ? $info['cus_state'] : null; // string (50) State of your customer. Not mandatory but useful if provided 397 | $this->data['cus_postcode'] = $info['cus_postcode']; // string (30) Mandatory - Postcode of your customer. Not mandatory but useful if provided 398 | $this->data['cus_country'] = $info['cus_country']; // string (50) Mandatory - Country of your customer. Not mandatory but useful if provided 399 | $this->data['cus_phone'] = $info['cus_phone']; // string (20) Mandatory - The phone/mobile number of your customer to contact if any issue arises 400 | $this->data['cus_fax'] = (isset($info['cus_fax'])) ? $info['cus_fax'] : null; // string (20) Fax number of your customer. Not mandatory but useful if provided 401 | 402 | return $this->data; 403 | } 404 | 405 | public function setShipmentInfo(array $info) 406 | { 407 | 408 | $this->data['shipping_method'] = $info['shipping_method']; // string (50) Mandatory - Shipping method of the order. Example: YES or NO or Courier 409 | $this->data['num_of_item'] = $info['num_of_item']; // integer (1) Mandatory - No of product will be shipped. Example: 1 or 2 or etc 410 | $this->data['ship_name'] = $info['ship_name']; // string (50) Mandatory, if shipping_method is YES - Shipping Address of your order. Not mandatory but useful if provided 411 | $this->data['ship_add1'] = $info['ship_add1']; // string (50) Mandatory, if shipping_method is YES - Additional Shipping Address of your order. Not mandatory but useful if provided 412 | $this->data['ship_add2'] = (isset($info['ship_add2'])) ? $info['ship_add2'] : null; // string (50) Additional Shipping Address of your order. Not mandatory but useful if provided 413 | $this->data['ship_city'] = $info['ship_city']; // string (50) Mandatory, if shipping_method is YES - Shipping city of your order. Not mandatory but useful if provided 414 | $this->data['ship_state'] = (isset($info['ship_state'])) ? $info['ship_state'] : null; // string (50) Shipping state of your order. Not mandatory but useful if provided 415 | $this->data['ship_postcode'] = (isset($info['ship_postcode'])) ? $info['ship_postcode'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping postcode of your order. Not mandatory but useful if provided 416 | $this->data['ship_country'] = (isset($info['ship_country'])) ? $info['ship_country'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping country of your order. Not mandatory but useful if provided 417 | 418 | return $this->data; 419 | } 420 | 421 | public function setProductInfo(array $info) 422 | { 423 | 424 | $this->data['product_name'] = (isset($info['product_name'])) ? $info['product_name'] : ''; // String (256) Mandatory - Mention the product name briefly. Mention the product name by coma separate. Example: Computer,Speaker 425 | $this->data['product_category'] = (isset($info['product_category'])) ? $info['product_category'] : ''; // String (100) Mandatory - Mention the product category. Example: Electronic or topup or bus ticket or air ticket 426 | 427 | /* 428 | * String (100) 429 | * Mandatory - Mention goods vertical. It is very much necessary for online transactions to avoid chargeback. 430 | * Please use the below keys : 431 | 1) general 432 | 2) physical-goods 433 | 3) non-physical-goods 434 | 4) airline-tickets 435 | 5) travel-vertical 436 | 6) telecom-vertical 437 | */ 438 | $this->data['product_profile'] = (isset($info['product_profile'])) ? $info['product_profile'] : ''; 439 | 440 | $this->data['hours_till_departure'] = (isset($info['hours_till_departure'])) ? $info['hours_till_departure'] : null; // string (30) Mandatory, if product_profile is airline-tickets - Provide the remaining time of departure of flight till at the time of purchasing the ticket. Example: 12 hrs or 36 hrs 441 | $this->data['flight_type'] = (isset($info['flight_type'])) ? $info['flight_type'] : null; // string (30) Mandatory, if product_profile is airline-tickets - Provide the flight type. Example: Oneway or Return or Multistop 442 | $this->data['pnr'] = (isset($info['pnr'])) ? $info['pnr'] : null; // string (50) Mandatory, if product_profile is airline-tickets - Provide the PNR. 443 | $this->data['journey_from_to'] = (isset($info['journey_from_to'])) ? $info['journey_from_to'] : null; // string (256) - Mandatory, if product_profile is airline-tickets - Provide the journey route. Example: DAC-CGP or DAC-CGP CGP-DAC 444 | $this->data['third_party_booking'] = (isset($info['third_party_booking'])) ? $info['third_party_booking'] : null; // string (20) Mandatory, if product_profile is airline-tickets - No/Yes. Whether the ticket has been taken from third party booking system. 445 | $this->data['hotel_name'] = (isset($info['hotel_name'])) ? $info['hotel_name'] : null; // string (256) Mandatory, if product_profile is travel-vertical - Please provide the hotel name. Example: Sheraton 446 | $this->data['length_of_stay'] = (isset($info['length_of_stay'])) ? $info['length_of_stay'] : null; // string (30) Mandatory, if product_profile is travel-vertical - How long stay in hotel. Example: 2 days 447 | $this->data['check_in_time'] = (isset($info['check_in_time'])) ? $info['check_in_time'] : null; // string (30) Mandatory, if product_profile is travel-vertical - Checking hours for the hotel room. Example: 24 hrs 448 | $this->data['hotel_city'] = (isset($info['hotel_city'])) ? $info['hotel_city'] : null; // string (50) Mandatory, if product_profile is travel-vertical - Location of the hotel. Example: Dhaka 449 | $this->data['product_type'] = (isset($info['product_type'])) ? $info['product_type'] : null; // string (30) Mandatory, if product_profile is telecom-vertical - For mobile or any recharge, this information is necessary. Example: Prepaid or Postpaid 450 | $this->data['topup_number'] = (isset($info['topup_number'])) ? $info['topup_number'] : null; // string (150) Mandatory, if product_profile is telecom-vertical - Provide the mobile number which will be recharged. Example: 8801700000000 or 8801700000000,8801900000000 451 | $this->data['country_topup'] = (isset($info['country_topup'])) ? $info['country_topup'] : null; // string (30) Mandatory, if product_profile is telecom-vertical - Provide the country name in where the service is given. Example: Bangladesh 452 | 453 | /* 454 | * Type: JSON 455 | * JSON data with two elements. product : Max 255 characters, quantity : Quantity in numeric value and amount : Decimal (12,2) 456 | * Example: 457 | [{"product":"DHK TO BRS AC A1","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A2","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A3","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A4","quantity":"2","amount":"200.00"}] 458 | * */ 459 | $this->data['cart'] = (isset($info['cart'])) ? $info['cart'] : null; 460 | $this->data['product_amount'] = (isset($info['product_amount'])) ? $info['product_amount'] : null; // decimal (10,2) Product price which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 50.40 461 | $this->data['vat'] = (isset($info['vat'])) ? $info['vat'] : null; // decimal (10,2) The VAT included on the product price which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 4.00 462 | $this->data['discount_amount'] = (isset($info['discount_amount'])) ? $info['discount_amount'] : null; // decimal (10,2) Discount given on the invoice which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 2.00 463 | $this->data['convenience_fee'] = (isset($info['convenience_fee'])) ? $info['convenience_fee'] : null; // decimal (10,2) Any convenience fee imposed on the invoice which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 3.00 464 | 465 | return $this->data; 466 | } 467 | 468 | public function setAdditionalInfo(array $info) 469 | { 470 | $this->data['value_a'] = (isset($info['value_a'])) ? $info['value_a'] : null; // value_a [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory] 471 | $this->data['value_b'] = (isset($info['value_b'])) ? $info['value_b'] : null; // value_b [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory] 472 | $this->data['value_c'] = (isset($info['value_c'])) ? $info['value_c'] : null; // value_c [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory] 473 | $this->data['value_d'] = (isset($info['value_d'])) ? $info['value_d'] : null; // value_d [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory] 474 | 475 | return $this->data; 476 | } 477 | } 478 | -------------------------------------------------------------------------------- /orders.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `orders` ( 2 | `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 | `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 4 | `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 5 | `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, 6 | `amount` double DEFAULT NULL, 7 | `address` text COLLATE utf8_unicode_ci, 8 | `status` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, 9 | `transaction_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 10 | `currency` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL 11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 12 | 13 | -------------------------------------------------------------------------------- /pg_redirection/cancel.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | Transaction Failed - SSLCommerz 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 | Invalid Information.'; 24 | exit; 25 | } 26 | 27 | // Connect to database after confirming the request 28 | include(__DIR__ . "/../db_connection.php"); 29 | include(__DIR__ . "/../OrderTransaction.php"); 30 | 31 | $tran_id = trim($_POST['tran_id']); 32 | $ot = new OrderTransaction(); 33 | $sql = $ot->getRecordQuery($tran_id); 34 | $result = $conn_integration->query($sql); 35 | $row = $result->fetch_array(MYSQLI_ASSOC); 36 | 37 | if ($row['status'] == 'Pending' || $row['status'] == 'Canceled') : 38 | $sql = $ot->updateTransactionQuery($tran_id, 'Canceled'); 39 | 40 | if ($conn_integration->query($sql) === TRUE) : 41 | ?> 42 |

Transaction has been CANCELLED.

43 |
44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
Payment Details
Description
Transaction ID
Amount:
64 | 65 |

Error updating record:

" error; ?> 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
Payment Details
Transaction ID
Transaction Time
Payment Method
Bank Transaction ID
Amount
95 | 96 |

Invalid Information.

97 | 98 |
99 |
100 |
101 | -------------------------------------------------------------------------------- /pg_redirection/fail.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | Transaction Failed - SSLCommerz 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 | Invalid Information.'; 24 | exit; 25 | } 26 | 27 | // Connect to database after confirming the request 28 | include(__DIR__ . "/../db_connection.php"); 29 | include(__DIR__ . "/../OrderTransaction.php"); 30 | 31 | $tran_id = trim($_POST['tran_id']); 32 | $ot = new OrderTransaction(); 33 | $sql = $ot->getRecordQuery($tran_id); 34 | $result = $conn_integration->query($sql); 35 | $row = $result->fetch_array(MYSQLI_ASSOC); 36 | 37 | if ($row['status'] == 'Pending' || $row['status'] == 'Falied') : 38 | $sql = $ot->updateTransactionQuery($tran_id, 'Falied'); 39 | 40 | if ($conn_integration->query($sql) === TRUE) : 41 | ?> 42 |

Unfortunately your Transaction FAILED.

43 |
44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
Payment Details
Error
Transaction ID
Payment Method
Bank Transaction Id
Amount:
72 | 73 |

Error updating record:

" error; ?> 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
Payment Details
Transaction ID
Transaction Time
Payment Method
Bank Transaction ID
Amount
103 | 104 |

Invalid Information.

105 | 106 |
107 |
108 |
109 | -------------------------------------------------------------------------------- /pg_redirection/ipn.php: -------------------------------------------------------------------------------- 1 | 5 | ###### 6 | 7 | error_reporting(0); 8 | 9 | require_once __DIR__ . "/../lib/SslCommerzNotification.php"; 10 | include_once __DIR__ . "/../db_connection.php"; 11 | include_once __DIR__ . "/../OrderTransaction.php"; 12 | 13 | use SslCommerz\SslCommerzNotification; 14 | 15 | if (empty($_POST['tran_id']) || empty($_POST['status'])) { 16 | echo "Invalid Information."; 17 | exit; 18 | } 19 | 20 | $tran_id = $_POST['tran_id']; 21 | $status = $_POST['status']; 22 | 23 | $sslc = new SslCommerzNotification(); 24 | $ot = new OrderTransaction(); 25 | 26 | $sql = $ot->getRecordQuery($tran_id); 27 | $result = $conn_integration->query($sql); 28 | $row = $result->fetch_array(MYSQLI_ASSOC); 29 | 30 | if (empty($row)) { 31 | echo "Invalid Transaction ID."; 32 | exit; 33 | } 34 | 35 | switch ($status) { 36 | case 'VALID': 37 | 38 | if ($row['status'] == 'Pending') { 39 | 40 | $amount = $_POST['amount']; 41 | $currency = $_POST['currency']; 42 | 43 | if (empty($_POST['amount']) || empty($_POST['currency'])) { 44 | 45 | echo "Invalid Information."; 46 | exit; 47 | 48 | } 49 | 50 | $validation = $sslc->orderValidate($_POST, $tran_id, $amount, $currency); 51 | 52 | if ($validation == true) { 53 | 54 | $sql = $ot->updateTransactionQuery($tran_id, 'Processing'); 55 | 56 | if ($conn_integration->query($sql) === true) { 57 | echo "Payment Record Updated Successfully"; 58 | } else { 59 | echo "Error updating record: " . $conn_integration->error; 60 | } 61 | 62 | } else { 63 | 64 | $sql = $ot->updateTransactionQuery($tran_id, 'Failed'); 65 | $conn_integration->query($sql); 66 | echo "Payment was not valid"; 67 | 68 | } 69 | 70 | } else if ($row['status'] == 'Processing') { 71 | 72 | echo "This order is already Successful"; 73 | 74 | } 75 | 76 | break; 77 | 78 | case 'FAILED': 79 | 80 | $sql = $ot->updateTransactionQuery($tran_id, 'Failed'); 81 | $conn_integration->query($sql); 82 | 83 | echo "Payment was failed"; 84 | 85 | break; 86 | 87 | case 'CANCELLED': 88 | 89 | $sql = $ot->updateTransactionQuery($tran_id, 'Cancelled'); 90 | $conn_integration->query($sql); 91 | 92 | echo "Payment was Cancelled"; 93 | 94 | break; 95 | 96 | default: 97 | 98 | echo "Invalid Information."; 99 | 100 | break; 101 | } 102 | -------------------------------------------------------------------------------- /pg_redirection/success.php: -------------------------------------------------------------------------------- 1 | 6 | # Prabal Mallick 7 | ###### 8 | 9 | error_reporting(0); 10 | ini_set('display_errors', 0); 11 | ?> 12 | 13 | 14 | 15 | 16 | Successful Transaction - SSLCommerz 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 | 25 | getRecordQuery($tran_id); 39 | $result = $conn_integration->query($sql); 40 | $row = $result->fetch_array(MYSQLI_ASSOC); 41 | 42 | if ($row['status'] == 'Pending' || $row['status'] == 'Processing') { 43 | $validated = $sslc->orderValidate($_POST, $tran_id, $amount, $currency); 44 | 45 | if ($validated) { 46 | $sql = $ot->updateTransactionQuery($tran_id, 'Processing'); 47 | 48 | if ($conn_integration->query($sql) === TRUE) { ?> 49 |

Congratulations! Your Transaction is Successful.

50 |
51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
Payment Details
Transaction ID
Transaction Time
Payment Method
Bank Transaction ID
Amount
78 | 79 | Error updating record: ' . $conn_integration->error; 84 | 85 | } // update query successful or not 86 | 87 | } else { // $validated is false 88 | 89 | echo '

Payment was not valid. Please contact with the merchant.

'; 90 | 91 | } // check if validated or not 92 | 93 | } else { // status is something else 94 | 95 | echo '

Invalid Information.

'; 96 | 97 | } // status is 'Pending' or already 'Processing' 98 | ?> 99 | 100 |
101 |
102 |
103 | 104 | --------------------------------------------------------------------------------