Skip to content

Commit a3e59ca

Browse files
authored
Merge pull request #1 from TechTailor/analysis-JGMNPV
Apply fixes from StyleCI
2 parents a59a1bc + f802783 commit a3e59ca

File tree

3 files changed

+91
-85
lines changed

3 files changed

+91
-85
lines changed

config/paytm.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
| Paytm Payment Gateway (PG)
88
|---------------------------------------------------------------------------------
99
|
10-
| Use Paytm Payment gateway solution in your App or website to simplify payment
11-
| for your customers. Your customers can choose to pay from any credit/debit card,
10+
| Use Paytm Payment gateway solution in your App or website to simplify payment
11+
| for your customers. Your customers can choose to pay from any credit/debit card,
1212
| UPI, Netbanking, Paytm Wallet and EMI.
1313
|
1414
|---------------------------------------------------------------------------------
@@ -37,12 +37,12 @@
3737
|
3838
| PayTM provides two seperate endpoints/url for testing and production
3939
| environments respectively.
40-
|
40+
|
4141
| More details: https://business.paytm.com/docs/jscheckout-test-go-live
4242
|
4343
*/
4444
'url' => [
45-
'testing' => 'https://securegw-stage.paytm.in', // DO NOT CHANGE
45+
'testing' => 'https://securegw-stage.paytm.in', // DO NOT CHANGE
4646
'production' => 'https://securegw.paytm.in', // DO NOT CHANGE
4747
],
4848

@@ -55,29 +55,29 @@
5555
| once payment process is completed. You can also setup a general callback
5656
| url in the Paytm Business Dashboard. You can also pass callback: false
5757
| from the JS call to receive and handle callback data in-page without refresh.
58-
|
58+
|
5959
| More details: https://business.paytm.com/docs/jscheckout-verify-payment?ref=jsCheckoutdoc
6060
|
6161
*/
6262
'callback_url' => env('PAYTM_CALLBACK_URL'),
63-
63+
6464
/*
6565
|--------------------------------------------------------------------------
6666
| MARCHANT CREDENTIALS
6767
|--------------------------------------------------------------------------
6868
|
69-
| Merchant ID & Merchant Key can be obtained from the PayTM Business
69+
| Merchant ID & Merchant Key can be obtained from the PayTM Business
7070
| Dashboard. Beaware not to share these credentials with anyone.
7171
|
72-
| Website must be set to "WEBSTAGING" for the testing environment and
72+
| Website must be set to "WEBSTAGING" for the testing environment and
7373
| set to "DEFAULT" for the production environment.
74-
|
74+
|
7575
| PayTM Business Dashboard: https://dashboard.paytm.com/next/apikeys
7676
|
7777
*/
7878
'merchant' => [
79-
'id' => env('PAYTM_MERCHANT_ID'),
80-
'key' => env('PAYTM_MERCHANT_KEY'),
79+
'id' => env('PAYTM_MERCHANT_ID'),
80+
'key' => env('PAYTM_MERCHANT_KEY'),
8181
'website' => env('PAYTM_WEBSITE', 'WEBSTAGING'), // WEBSTAGING or DEFAULT
8282
],
8383

@@ -86,9 +86,9 @@
8686
| UNIQUE ORDER ID PREFIX
8787
|--------------------------------------------------------------------------
8888
|
89-
| This is a unique prefix that you can add to the Order Id's when
89+
| This is a unique prefix that you can add to the Order Id's when
9090
| generating the transaction token for the Paytm PG.
91-
|
91+
|
9292
| Ex: "PAYTM_BLINK_" will generate id as "PAYTM_BLINK_212414589",
9393
| "PAYTM_ORDERID_" will generate id as "PAYTM_ORDERID_121154589", etc.
9494
|

src/Paytm.php

Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,112 +8,118 @@ class Paytm
88
{
99
/**
1010
* Generate a transaction token for the PayTM PG.
11-
*
11+
*
1212
* @param float $amount
1313
* @param array $customer
14+
*
1415
* @return array $result
1516
*/
1617
public function getTransactionToken($amount, $customer)
1718
{
1819
// Generate a unique order id using the order_id_prefix.
19-
$newOrderId = config('paytm.order_id_prefix') . time();
20-
20+
$newOrderId = config('paytm.order_id_prefix').time();
21+
2122
// Prepare the JSON string for request.
22-
$paytmParams["body"] = array(
23-
"requestType" => "Payment", // Request Type
24-
"mid" => config('paytm.merchant.id'), // Paytm Merchant ID
25-
"websiteName" => config('paytm.website'), // Paytm Website
26-
"orderId" => $newOrderId,
27-
"callbackUrl" => config('paytm.callback_url'), // Callback url for processing responses from paytm
28-
"txnAmount" => array(
29-
"value" => $amount,
30-
"currency" => "INR", // Only INR Supported
31-
),
32-
"userInfo" => array(
33-
"custId" => $customer['custId'], // Mandatory
34-
'mobile' => $customer['mobile'] ?? null, // Optional
35-
'email' => $customer['email'] ?? null, // Optional
36-
'firstName' => $customer['firstName'] ?? null, // Optional
37-
'lastName' => $customer['lastName'] ?? null, // Optional
38-
),
39-
);
40-
41-
// Generate a unique signature using PaytmChecksumhash.
42-
$generateSignature = PaytmChecksum::generateSignature(json_encode($paytmParams['body'], JSON_UNESCAPED_SLASHES), config('paytm.merchant.key'));
43-
44-
// Add the generated signature to the parameters for posting.
45-
$paytmParams["head"] = array("signature" => $generateSignature);
46-
47-
// Set the api endpoint for the local, testing or staging environment
48-
if(config('paytm.environment') == 'testing')
49-
$url = config('paytm.url.testing')."/theia/api/v1/initiateTransaction?mid=". config('paytm.merchant.id') ."&orderId=". $newOrderId;
50-
51-
// Set the api endpoint for the production environment
52-
elseif (config('paytm.environment' == 'production'))
53-
$url = config('paytm.url.production')."/theia/api/v1/initiateTransaction?mid=". config('paytm.merchant.id') ."&orderId=". $newOrderId;
54-
55-
// Send an api request to PayTM.
56-
$response = $this->getcURLRequest($url, $paytmParams);
57-
58-
// Evaluate the response and return appropriate result.
59-
if (!empty($response['body']['resultInfo']['resultStatus']) && $response['body']['resultInfo']['resultStatus'] == 'S') {
60-
$result = array('success' => true, 'orderId' => $newOrderId, 'txnToken' => $response['body']['txnToken'], 'amount' => $amount, 'message' => $response['body']['resultInfo']['resultMsg']);
61-
}
62-
else {
63-
$result = array('success' => false, 'orderId' => $newOrderId, 'txnToken' => '', 'amount' => $amount, 'message' => $response['body']['resultInfo']['resultMsg']);
64-
}
23+
$paytmParams['body'] = [
24+
'requestType' => 'Payment', // Request Type
25+
'mid' => config('paytm.merchant.id'), // Paytm Merchant ID
26+
'websiteName' => config('paytm.website'), // Paytm Website
27+
'orderId' => $newOrderId,
28+
'callbackUrl' => config('paytm.callback_url'), // Callback url for processing responses from paytm
29+
'txnAmount' => [
30+
'value' => $amount,
31+
'currency' => 'INR', // Only INR Supported
32+
],
33+
'userInfo' => [
34+
'custId' => $customer['custId'], // Mandatory
35+
'mobile' => $customer['mobile'] ?? null, // Optional
36+
'email' => $customer['email'] ?? null, // Optional
37+
'firstName' => $customer['firstName'] ?? null, // Optional
38+
'lastName' => $customer['lastName'] ?? null, // Optional
39+
],
40+
];
41+
42+
// Generate a unique signature using PaytmChecksumhash.
43+
$generateSignature = PaytmChecksum::generateSignature(json_encode($paytmParams['body'], JSON_UNESCAPED_SLASHES), config('paytm.merchant.key'));
44+
45+
// Add the generated signature to the parameters for posting.
46+
$paytmParams['head'] = ['signature' => $generateSignature];
47+
48+
// Set the api endpoint for the local, testing or staging environment
49+
if (config('paytm.environment') == 'testing') {
50+
$url = config('paytm.url.testing').'/theia/api/v1/initiateTransaction?mid='.config('paytm.merchant.id').'&orderId='.$newOrderId;
51+
}
52+
53+
// Set the api endpoint for the production environment
54+
elseif (config('paytm.environment' == 'production')) {
55+
$url = config('paytm.url.production').'/theia/api/v1/initiateTransaction?mid='.config('paytm.merchant.id').'&orderId='.$newOrderId;
56+
}
57+
58+
// Send an api request to PayTM.
59+
$response = $this->getcURLRequest($url, $paytmParams);
60+
61+
// Evaluate the response and return appropriate result.
62+
if (!empty($response['body']['resultInfo']['resultStatus']) && $response['body']['resultInfo']['resultStatus'] == 'S') {
63+
$result = ['success' => true, 'orderId' => $newOrderId, 'txnToken' => $response['body']['txnToken'], 'amount' => $amount, 'message' => $response['body']['resultInfo']['resultMsg']];
64+
} else {
65+
$result = ['success' => false, 'orderId' => $newOrderId, 'txnToken' => '', 'amount' => $amount, 'message' => $response['body']['resultInfo']['resultMsg']];
66+
}
6567

6668
// Return result array.
67-
return $result;
68-
}
69+
return $result;
70+
}
6971

7072
/**
7173
* Verify the status of a transaction/order.
72-
*
74+
*
7375
* @param string $orderId
76+
*
7477
* @return $response
7578
*/
7679
public function getTransactionStatus($orderId)
77-
{
78-
// initialize an array
79-
$paytmParams = array();
80+
{
81+
// initialize an array
82+
$paytmParams = [];
8083

81-
// set parameters
82-
$paytmParams["body"] = array(
83-
"mid" => config('paytm.merchant.id'), // Paytm Merchant ID
84-
"orderId" => $orderId,
85-
);
84+
// set parameters
85+
$paytmParams['body'] = [
86+
'mid' => config('paytm.merchant.id'), // Paytm Merchant ID
87+
'orderId' => $orderId,
88+
];
8689

8790
// Generate a unique signature using PaytmChecksumhash.
88-
$generateSignature = PaytmChecksum::generateSignature(json_encode($paytmParams["body"], JSON_UNESCAPED_SLASHES), config('paytm.merchant.key'));
91+
$generateSignature = PaytmChecksum::generateSignature(json_encode($paytmParams['body'], JSON_UNESCAPED_SLASHES), config('paytm.merchant.key'));
8992

90-
// Add the generated signature to the parameters for posting.
91-
$paytmParams["head"] = array("signature" => $generateSignature);
93+
// Add the generated signature to the parameters for posting.
94+
$paytmParams['head'] = ['signature' => $generateSignature];
9295

9396
// Set the api endpoint for the testing environment
94-
if (config('paytm.environment') == 'testing')
95-
$url = config('paytm.url.testing') . "/v3/order/status";
97+
if (config('paytm.environment') == 'testing') {
98+
$url = config('paytm.url.testing').'/v3/order/status';
99+
}
96100

97101
// Set the api endpoint for the production environment
98-
elseif (config('paytm.environment' == 'production'))
99-
$url = config('paytm.url.production') . "/v3/order/status";
100-
102+
elseif (config('paytm.environment' == 'production')) {
103+
$url = config('paytm.url.production').'/v3/order/status';
104+
}
105+
101106
// Send an api request to PayTM.
102-
$response = $this->getcURLRequest($url, $paytmParams);
107+
$response = $this->getcURLRequest($url, $paytmParams);
103108

104109
// Return response.
105-
return $response;
106-
}
110+
return $response;
111+
}
107112

108113
/**
109114
* Send a POST request to the PayTM API endpoint.
110-
*
115+
*
111116
* @param $url
112117
* @param $postDate
113118
* @param $headers
119+
*
114120
* @return $response
115121
*/
116-
public function getcURLRequest($url, $postData = array(), $headers = array("Content-Type: application/json"))
122+
public function getcURLRequest($url, $postData = [], $headers = ['Content-Type: application/json'])
117123
{
118124
// Encode the JSON string for the request
119125
$post_data_string = json_encode($postData, JSON_UNESCAPED_SLASHES);
@@ -123,7 +129,7 @@ public function getcURLRequest($url, $postData = array(), $headers = array("Cont
123129
curl_setopt($ch, CURLOPT_POST, 1);
124130
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data_string);
125131
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
126-
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
132+
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
127133
$response = curl_exec($ch);
128134

129135
// Return response.

src/PaytmBladeDirectives.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PaytmBladeDirectives
66
{
77
public static function paytmScripts(string $expression): string
88
{
9-
return <<<HTML
9+
return <<<'HTML'
1010
<script type="application/javascript" crossorigin="anonymous" src="{{ config('paytm.url.testing') }}/merchantpgpui/checkoutjs/merchants/{{ config('paytm.merchant.id') }}.js"></script>
1111
<script src="{{ asset('vendor/paytm/js/paytm.js') }}" data-turbo-eval="false" data-turbolinks-eval="false"></script>
1212
HTML;

0 commit comments

Comments
 (0)