├── LICENSE ├── PaytmKit ├── TxnStatus.php ├── TxnTest.php ├── lib │ ├── config_paytm.php │ └── encdec_paytm.php ├── pgRedirect.php └── pgResponse.php ├── README.md ├── index.php └── response.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Chandan Sharma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PaytmKit/TxnStatus.php: -------------------------------------------------------------------------------- 1 | PAYTM_MERCHANT_MID , "ORDERID" => $ORDER_ID); 21 | 22 | $StatusCheckSum = getChecksumFromArray($requestParamList,PAYTM_MERCHANT_KEY); 23 | 24 | $requestParamList['CHECKSUMHASH'] = $StatusCheckSum; 25 | 26 | // Call the PG's getTxnStatusNew() function for verifying the transaction status. 27 | $responseParamList = getTxnStatusNew($requestParamList); 28 | } 29 | 30 | ?> 31 | 32 | 33 | 34 | Transaction status query 35 | 36 | 37 | 38 |

Transaction status query

39 |
40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
45 |
53 |

54 | 0 ) 56 | { 57 | ?> 58 |

Response of status query:

59 | 60 | 61 | $paramValue) { 63 | ?> 64 | 65 | 66 | 67 | 68 | 71 | 72 |
73 | 76 |
77 | 78 | -------------------------------------------------------------------------------- /PaytmKit/TxnTest.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | Merchant Check Out Page 11 | 12 | 13 | 14 |

Merchant Check Out Page

15 |
16 | 	
17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
S.NoLabelValue
1"> 31 |
2
3
4 48 |
5 56 |
65 | * - Mandatory Fields 66 |
67 | 68 | -------------------------------------------------------------------------------- /PaytmKit/lib/config_paytm.php: -------------------------------------------------------------------------------- 1 | | 8 | *| @Website: | 9 | *|======================================================================| 10 | */ 11 | 12 | 13 | /* 14 | - Use PAYTM_ENVIRONMENT as 'PROD' if you wanted to do transaction in production environment else 'TEST' for doing transaction in testing environment. 15 | - Change the value of PAYTM_MERCHANT_KEY constant with details received from Paytm. 16 | - Change the value of PAYTM_MERCHANT_MID constant with details received from Paytm. 17 | - Change the value of PAYTM_MERCHANT_WEBSITE constant with details received from Paytm. 18 | - Above details will be different for testing and production environment. 19 | */ 20 | 21 | // define('PAYTM_ENVIRONMENT', 'TEST'); // PROD 22 | // define('PAYTM_MERCHANT_KEY', 'O0zUdIG%OQViK_'); //Change this constant's value with Merchant key received from Paytm. 23 | // define('PAYTM_MERCHANT_MID', 'dZlzzF171371019'); //Change this constant's value with MID (Merchant ID) received from Paytm. 24 | // define('PAYTM_MERCHANT_WEBSITE', 'WEBSTAGING'); //Change this constant's value with Website name received from Paytm. 25 | 26 | 27 | //================================================= 28 | // For PayTM Settings:: 29 | //================================================= 30 | 31 | $PAYTM_ENVIRONMENT = "PROD"; // For Production /LIVE 32 | $PAYTM_ENVIRONMENT = "TEST"; // For Staging / TEST 33 | 34 | if(!defined("PAYTM_ENVIRONMENT") ){ 35 | define('PAYTM_ENVIRONMENT', $PAYTM_ENVIRONMENT); 36 | } 37 | 38 | // For LIVE 39 | if (PAYTM_ENVIRONMENT == 'PROD') { 40 | //=================================================== 41 | // For Production or LIVE Credentials 42 | //=================================================== 43 | $PAYTM_STATUS_QUERY_NEW_URL='https://securegw.paytm.in/merchant-status/getTxnStatus'; 44 | $PAYTM_TXN_URL='https://securegw.paytm.in/theia/processTransaction'; 45 | 46 | //Change this constant's value with Merchant key received from Paytm. 47 | $PAYTM_MERCHANT_MID = "ENTER_YOUR_MERCHANT_ID"; 48 | $PAYTM_MERCHANT_KEY = "ENTER_YOUR_MERCHANT_KEY"; 49 | 50 | $PAYTM_CHANNEL_ID = "WEB"; 51 | $PAYTM_INDUSTRY_TYPE_ID = ""; 52 | $PAYTM_MERCHANT_WEBSITE = ""; 53 | $PAYTM_CALLBACK_URL = ""; 54 | 55 | }else{ 56 | //=================================================== 57 | // For Staging or TEST Credentials 58 | //=================================================== 59 | $PAYTM_STATUS_QUERY_NEW_URL='https://securegw-stage.paytm.in/merchant-status/getTxnStatus'; 60 | $PAYTM_TXN_URL='https://securegw-stage.paytm.in/theia/processTransaction'; 61 | 62 | //Change this constant's value with Merchant key received from Paytm. 63 | $PAYTM_MERCHANT_MID = "ENTER_YOUR_MERCHANT_ID"; 64 | $PAYTM_MERCHANT_KEY = "ENTER_YOUR_MERCHANT_KEY"; 65 | 66 | $PAYTM_CHANNEL_ID = "WEB"; 67 | $PAYTM_INDUSTRY_TYPE_ID = "Retail"; 68 | $PAYTM_MERCHANT_WEBSITE = "WEBSTAGING"; 69 | 70 | $PAYTM_CALLBACK_URL = "http://127.0.0.1/devchandan/payment-using-paytm/response.php"; 71 | 72 | } 73 | 74 | define('PAYTM_MERCHANT_KEY', $PAYTM_MERCHANT_KEY); 75 | define('PAYTM_MERCHANT_MID', $PAYTM_MERCHANT_MID); 76 | 77 | define("PAYTM_MERCHANT_WEBSITE", $PAYTM_MERCHANT_WEBSITE); 78 | define("PAYTM_CHANNEL_ID", $PAYTM_CHANNEL_ID); 79 | define("PAYTM_INDUSTRY_TYPE_ID", $PAYTM_INDUSTRY_TYPE_ID); 80 | define("PAYTM_CALLBACK_URL", $PAYTM_CALLBACK_URL); 81 | 82 | 83 | define('PAYTM_REFUND_URL', ''); 84 | define('PAYTM_STATUS_QUERY_URL', $PAYTM_STATUS_QUERY_NEW_URL); 85 | define('PAYTM_STATUS_QUERY_NEW_URL', $PAYTM_STATUS_QUERY_NEW_URL); 86 | define('PAYTM_TXN_URL', $PAYTM_TXN_URL); 87 | 88 | ?> 89 | -------------------------------------------------------------------------------- /PaytmKit/lib/encdec_paytm.php: -------------------------------------------------------------------------------- 1 | $value) { 105 | $pos = strpos($value, $findme); 106 | $pospipe = strpos($value, $findmepipe); 107 | if ($pos !== false || $pospipe !== false) 108 | { 109 | continue; 110 | } 111 | 112 | if ($flag) { 113 | $paramStr .= checkString_e($value); 114 | $flag = 0; 115 | } else { 116 | $paramStr .= "|" . checkString_e($value); 117 | } 118 | } 119 | return $paramStr; 120 | } 121 | 122 | function getArray2StrForVerify($arrayList) { 123 | $paramStr = ""; 124 | $flag = 1; 125 | foreach ($arrayList as $key => $value) { 126 | if ($flag) { 127 | $paramStr .= checkString_e($value); 128 | $flag = 0; 129 | } else { 130 | $paramStr .= "|" . checkString_e($value); 131 | } 132 | } 133 | return $paramStr; 134 | } 135 | 136 | function redirect2PG($paramList, $key) { 137 | $hashString = getchecksumFromArray($paramList); 138 | $checksum = encrypt_e($hashString, $key); 139 | } 140 | 141 | function removeCheckSumParam($arrayList) { 142 | if (isset($arrayList["CHECKSUMHASH"])) { 143 | unset($arrayList["CHECKSUMHASH"]); 144 | } 145 | return $arrayList; 146 | } 147 | 148 | function getTxnStatus($requestParamList) { 149 | return callAPI(PAYTM_STATUS_QUERY_URL, $requestParamList); 150 | } 151 | 152 | function getTxnStatusNew($requestParamList) { 153 | return callNewAPI(PAYTM_STATUS_QUERY_NEW_URL, $requestParamList); 154 | } 155 | 156 | function initiateTxnRefund($requestParamList) { 157 | $CHECKSUM = getRefundChecksumFromArray($requestParamList,PAYTM_MERCHANT_KEY,0); 158 | $requestParamList["CHECKSUM"] = $CHECKSUM; 159 | return callAPI(PAYTM_REFUND_URL, $requestParamList); 160 | } 161 | 162 | function callAPI($apiURL, $requestParamList) { 163 | $jsonResponse = ""; 164 | $responseParamList = array(); 165 | $JsonData =json_encode($requestParamList); 166 | $postData = 'JsonData='.urlencode($JsonData); 167 | $ch = curl_init($apiURL); 168 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 169 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 170 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 171 | curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 172 | curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 173 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( 174 | 'Content-Type: application/json', 175 | 'Content-Length: ' . strlen($postData)) 176 | ); 177 | $jsonResponse = curl_exec($ch); 178 | $responseParamList = json_decode($jsonResponse,true); 179 | return $responseParamList; 180 | } 181 | 182 | function callNewAPI($apiURL, $requestParamList) { 183 | $jsonResponse = ""; 184 | $responseParamList = array(); 185 | $JsonData =json_encode($requestParamList); 186 | $postData = 'JsonData='.urlencode($JsonData); 187 | $ch = curl_init($apiURL); 188 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 189 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 190 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 191 | curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 192 | curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 193 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( 194 | 'Content-Type: application/json', 195 | 'Content-Length: ' . strlen($postData)) 196 | ); 197 | $jsonResponse = curl_exec($ch); 198 | $responseParamList = json_decode($jsonResponse,true); 199 | return $responseParamList; 200 | } 201 | function getRefundChecksumFromArray($arrayList, $key, $sort=1) { 202 | if ($sort != 0) { 203 | ksort($arrayList); 204 | } 205 | $str = getRefundArray2Str($arrayList); 206 | $salt = generateSalt_e(4); 207 | $finalString = $str . "|" . $salt; 208 | $hash = hash("sha256", $finalString); 209 | $hashString = $hash . $salt; 210 | $checksum = encrypt_e($hashString, $key); 211 | return $checksum; 212 | } 213 | function getRefundArray2Str($arrayList) { 214 | $findmepipe = '|'; 215 | $paramStr = ""; 216 | $flag = 1; 217 | foreach ($arrayList as $key => $value) { 218 | $pospipe = strpos($value, $findmepipe); 219 | if ($pospipe !== false) 220 | { 221 | continue; 222 | } 223 | 224 | if ($flag) { 225 | $paramStr .= checkString_e($value); 226 | $flag = 0; 227 | } else { 228 | $paramStr .= "|" . checkString_e($value); 229 | } 230 | } 231 | return $paramStr; 232 | } 233 | function callRefundAPI($refundApiURL, $requestParamList) { 234 | $jsonResponse = ""; 235 | $responseParamList = array(); 236 | $JsonData =json_encode($requestParamList); 237 | $postData = 'JsonData='.urlencode($JsonData); 238 | $ch = curl_init($apiURL); 239 | curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 240 | curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 241 | curl_setopt($ch, CURLOPT_URL, $refundApiURL); 242 | curl_setopt($ch, CURLOPT_POST, true); 243 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 244 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 245 | $headers = array(); 246 | $headers[] = 'Content-Type: application/json'; 247 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 248 | $jsonResponse = curl_exec($ch); 249 | $responseParamList = json_decode($jsonResponse,true); 250 | return $responseParamList; 251 | } 252 | -------------------------------------------------------------------------------- /PaytmKit/pgRedirect.php: -------------------------------------------------------------------------------- 1 | 40 | 41 | 42 | Merchant Check Out Page 43 | 44 | 45 |

Please do not refresh this page...

46 |
47 | 48 | 49 | $value) { 51 | echo ''; 52 | } 53 | ?> 54 | 55 | 56 |
57 | 60 |
61 | 62 | -------------------------------------------------------------------------------- /PaytmKit/pgResponse.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devchandansh/payment-using-paytm-php/d729b9f8a446e204d9ff8dbf2467d7d9b4ecc7f2/PaytmKit/pgResponse.php -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # payment-using-paytm-php 2 | PayTM Payment Gateway Integration in Core PHP. 3 | Payment Gateway Integration in the Website in Core PHP. 4 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | "); 18 | 19 | $orderId = time(); 20 | $txnAmount = "100.50"; 21 | $custId = "cust123"; 22 | $mobileNo = "7777777777"; 23 | $email = "username@emailprovider.com"; 24 | 25 | $paytmParams = array(); 26 | $paytmParams["ORDER_ID"] = $orderId; 27 | $paytmParams["CUST_ID"] = $custId; 28 | $paytmParams["MOBILE_NO"] = $mobileNo; 29 | $paytmParams["EMAIL"] = $email; 30 | $paytmParams["TXN_AMOUNT"] = $txnAmount; 31 | $paytmParams["MID"] = PAYTM_MERCHANT_MID; 32 | $paytmParams["CHANNEL_ID"] = PAYTM_CHANNEL_ID; 33 | $paytmParams["WEBSITE"] = PAYTM_MERCHANT_WEBSITE; 34 | $paytmParams["INDUSTRY_TYPE_ID"] = PAYTM_INDUSTRY_TYPE_ID; 35 | $paytmParams["CALLBACK_URL"] = PAYTM_CALLBACK_URL; 36 | $paytmChecksum = getChecksumFromArray($paytmParams, PAYTM_MERCHANT_KEY); 37 | $transactionURL = PAYTM_TXN_URL; 38 | // $transactionURL = "https://securegw-stage.paytm.in/theia/processTransaction"; 39 | // $transactionURL = "https://securegw.paytm.in/theia/processTransaction"; // for production 40 | ?> 41 | 42 | 43 | Merchant Checkout Page 44 | 45 | 46 |

Please do not refresh this page...

47 |
48 | $value) { 50 | echo ''; 51 | } 52 | ?> 53 | 54 | 55 |
56 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /response.php: -------------------------------------------------------------------------------- 1 | Checksum matched and following are the transaction details:" . "
"; 23 | 24 | echo "
";
25 | 	print_r($_POST);
26 | 	echo "
";
27 | 
28 | 	if ($_POST["STATUS"] == "TXN_SUCCESS") {
29 | 		echo "Transaction status is success" . "
"; 30 | //Process your transaction here as success transaction. 31 | //Verify amount & order id received from Payment gateway with your application's order id and amount. 32 | } 33 | else { 34 | echo "Transaction status is failure" . "
"; 35 | } 36 | 37 | if (isset($_POST) && count($_POST)>0 ) 38 | { 39 | foreach($_POST as $paramName => $paramValue) { 40 | echo "
" . $paramName . " = " . $paramValue; 41 | } 42 | } 43 | 44 | 45 | } 46 | else { 47 | echo "Checksum mismatched."; 48 | //Process transaction as suspicious. 49 | } 50 | 51 | ?> --------------------------------------------------------------------------------