-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout_hosted.php
189 lines (149 loc) · 7.34 KB
/
checkout_hosted.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
72
73
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
//Hosted Checkout Process
//This process is as same as normal transaction initiation process. You have to redirect customer to GatewayPageURL
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once(__DIR__ . "/lib/SslCommerzNotification.php");
include("payment_dbconn.php");
include("OrderTransaction.php");
include("vendor/autoload.php");
use SslCommerz\SslCommerzNotification;
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
$STORE_ID = getenv('Store_ID');
$STORE_PASSWORD = getenv('Store_Password');
$STORE_NAME = getenv('Store_Name');
# Organize the submitted/inputted data
$post_data = array(); //declare an empty array
//by using array name with an index(here naming index), we are inserting values into the array (associative)
$post_data['total_amount'] = $_POST['amount']; //since the amount is hidden, it is not visible. So no need to use isset() for checking, just collect it from form using post
$post_data['currency'] = "BDT";
$post_data['tran_id'] = "TYISHL-SSLCZ_TEST_" . uniqid();
# CUSTOMER INFORMATION
//if(isset($_POST['customer_name'])){$post_data['cus_name'] = $_POST['customer_name'];} //replacement for ? :
$post_data['cus_name'] = isset($_POST['customer_name']) ? $_POST['customer_name'] : "John Doe";
$post_data['cus_id'] = isset($_POST['customer_id']) ? $_POST['customer_id'] : 1;
$post_data['cus_email'] = isset($_POST['customer_email']) ? $_POST['customer_email'] : "john.doe@email.com";
$post_data['cus_add1'] = isset($_POST['customer_address']) ? $_POST['customer_address'] : "Dhanmondi";
$post_data['cus_add2'] = "Dhaka";
$post_data['cus_city'] = "Dhaka";
$post_data['cus_state'] = isset($_POST['customer_state']) ? $_POST['customer_state'] : "Dhaka";
$post_data['cus_postcode'] = "1000";
$post_data['cus_country'] = "Bangladesh";
$post_data['cus_phone'] = isset($_POST['customer_mobile']) ? $_POST['customer_mobile'] : "01711111111";
$post_data['cus_fax'] = "01711111111";
$post_data['cus_zip'] = isset($_POST['zip_code']) ? $_POST['zip_code'] : "0000";
$post_data['cus_items'] = isset($_POST['items']) ? $_POST['items'] : "0";
$post_data['cus_order_pin'] = isset($_POST['customer_pin_code']) ? $_POST['customer_pin_code'] : "XXX";
$post_data['cus_order_identify'] = isset($_POST['customer_identify_num']) ? $_POST['customer_identify_num'] : "XXX";
# SHIPMENT INFORMATION (This concerns the store from where the customer made purchase - our details) (fixed)
$post_data['ship_name'] = "{$STORE_NAME}"; //store name
$post_data['ship_add1'] = "Dhanmondi, Road no. 7A, Jawwad City Center, 3rd Floor, Dhaka";
$post_data['ship_add2'] = "Dhaka";
$post_data['ship_city'] = "Dhaka";
$post_data['ship_state'] = "Dhaka";
$post_data['ship_postcode'] = "1576";
$post_data['ship_phone'] = "+8801715199382";
$post_data['ship_country'] = "Bangladesh";
$post_data['vat'] = 100; //vat on goods
$post_data['ship_date'] = isset($_POST['ship_date']) ? $_POST['ship_date'] : "2021";
# OPTIONAL PARAMETERS
$post_data['value_a'] = "Regent Air";
$post_data['value_b'] = "ref002";
$post_data['value_c'] = "ref003";
$post_data['value_d'] = "ref004";
# MANAGED TRANS
//$post_data['multi_card_name'] = "brac_visa,dbbl_visa,city_visa,ebl_visa,brac_master,dbbl_master,city_master,ebl_master,city_amex,qcash,dbbl_nexus,bankasia,abbank,ibbl,mtbl,city";
//$post_data['allowed_bin'] = "371598,371599,376947,376948,376949";
//$post_data['multi_card_name'] = "bankasia,mtbl,city";
# CART PARAMETERS
$post_data['cart'] = json_encode(array(
array("sku" => "REF0001", "product" => "DHK TO BRS AC A1", "quantity" => "1", "amount" => "200.00"),
array("sku" => "REF0002", "product" => "DHK TO BRS AC A2", "quantity" => "1", "amount" => "200.00"),
array("sku" => "REF0003", "product" => "DHK TO BRS AC A3", "quantity" => "1", "amount" => "200.00"),
array("sku" => "REF0004", "product" => "DHK TO BRS AC A4", "quantity" => "2", "amount" => "200.00")
));
$post_data['emi_option'] = "1";
//$post_data['emi_max_inst_option'] = "9";
//$post_data['emi_selected_inst'] = "24";
//$post_data['product_amount'] = "0";
$post_data['discount_amount'] = 0;
$post_data['delivery_charge'] = 50;
/*
$post_data['product_amount'] = "100";
$post_data['vat'] = "5";
$post_data['discount_amount'] = "5";
$post_data['convenience_fee'] = "3";
*/
//$post_data['discount_amount'] = "5";
//$post_data['multi_card_name'] = "brac_visa,brac_master";
//$post_data['allowed_bin'] = "408860,458763,489035,432147,432145,548895,545610,545538,432149,484096,484097,464573,539932,436475";
# RECURRING DATA
$schedule = array(
"refer" => "5B90BA91AA3F2", # Subscriber id which generated in Merchant Admin panel
"acct_no" => "01730671731",
"type" => "daily", # Recurring Schedule - monthly,weekly,daily
//"dayofmonth" => "24", # 1st day of every month
//"month" => "8", # 1st day of January for Yearly Recurring
//"week" => "sat", # In case, weekly recurring
);
# MORE THAN 20 Characaters - Alpha-Numeric - For Auto debit Instruction
# IT Will Return Transaction History
# IT Will Return Saved Card- Set Default and delete Option
//not using at the moment as it requires categories classification
$post_data["firstName"] = "John";
$post_data["lastName"] = "Doe";
$post_data["street"] = "93 B, New Eskaton Road";
$post_data["city"] = "Dhaka";
$post_data["state"] = "Dhaka";
$post_data["postalCode"] = "1000";
$post_data["country"] = "Bangladesh";
$post_data["email"] = "john.doe@email.com";
$post_data["product_category"] = "Electronic";
$post_data["product_name"] = "Computer";
$post_data["previous_customer"] = "Yes";
$post_data["shipping_method"] = "Courier";
$post_data["num_of_item"] = "1";
$post_data["product_shipping_contry"] = "Bangladesh";
$post_data["vip_customer"] = "YES";
$post_data["hours_till_departure"] = "12 hrs";
$post_data["flight_type"] = "Oneway";
$post_data["journey_from_to"] = "DAC-CGP";
$post_data["third_party_booking"] = "No";
$post_data["hotel_name"] = "Sheraton";
$post_data["length_of_stay"] = "2 days";
$post_data["check_in_time"] = "24 hrs";
$post_data["hotel_city"] = "Dhaka";
$post_data["product_type"] = "Prepaid";
$post_data["phone_number"] = "01711111111";
$post_data["country_topUp"] = "Bangladesh";
$post_data["shipToFirstName"] = "John";
$post_data["shipToLastName"] = "Doe";
$post_data["shipToStreet"] = "93 B, New Eskaton Road";
$post_data["shipToCity"] = "Dhaka";
$post_data["shipToState"] = "Dhaka";
$post_data["shipToPostalCode"] = "1000";
$post_data["shipToCountry"] = "Bangladesh";
$post_data["shipToEmail"] = "john.doe@email.com";
$post_data["ship_to_phone_number"] = "01711111111";
# SPECIAL PARAM
$post_data['tokenize_id'] = "1";
# 1 : Physical Goods
# 2 : Non-Physical Goods Vertical(software)
# 3 : Airline Vertical Profile
# 4 : Travel Vertical Profile
# 5 : Telecom Vertical Profile
$post_data["product_profile"] = "baby good";
$post_data["product_profile_id"] = "5";
$post_data["topup_number"] = "01711111111"; # topUpNumber
//-----------------------------END OF REST API (part 1)-----------------------------
# First, save the input data into local database table `orders`
$query = new OrderTransaction();
$sql = $query->saveTransactionQuery($post_data);
if ($conn_integration->query($sql) === TRUE) {
# Call the Payment Gateway Library
$sslcomz = new SslCommerzNotification();
$sslcomz->makePayment($post_data, 'hosted'); //$post_data is the array. hosted refers to the type of payment integration
} else {
echo "Error: " . $sql . "<br>" . $conn_integration->error;
}