@@ -134,6 +134,9 @@ |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | + /** |
|
138 | + * @param resource $curl |
|
139 | + */ |
|
137 | 140 | private static function closeCurl($curl,$payload) |
138 | 141 | { |
139 | 142 | curl_setopt($curl, CURLOPT_POST, true); |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use Lubusin\Mojo\Models\MojoRefundDetails; |
7 | 7 | use Exception; |
8 | 8 | use App\User; |
9 | -use DB; |
|
10 | 9 | |
11 | 10 | class Mojo |
12 | 11 | { |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $payload = self::createPaymentPayload($user, $amount, $purpose, $phone); |
28 | 28 | |
29 | - $response = self::closeCurl($curl,$payload); |
|
29 | + $response = self::closeCurl($curl,$payload); |
|
30 | 30 | |
31 | 31 | $finalResponse = json_decode($response); |
32 | 32 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | $curl = static::setupCURL("https://{$sub}.instamojo.com/api/1.1/refunds/"); |
67 | 67 | |
68 | 68 | $payload = ['payment_id' => $payment_id, |
69 | - 'type' => $type, |
|
70 | - 'body' => $reason ]; |
|
69 | + 'type' => $type, |
|
70 | + 'body' => $reason ]; |
|
71 | 71 | |
72 | 72 | $response = self::closeCurl($curl,$payload); |
73 | 73 | $afterDecoding = json_decode($response); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
126 | 126 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
127 | 127 | curl_setopt($ch, CURLOPT_HTTPHEADER,["X-Api-Key:{$api_key}", |
128 | - "X-Auth-Token:{$api_token}"]); |
|
128 | + "X-Auth-Token:{$api_token}"]); |
|
129 | 129 | return $ch; |
130 | 130 | |
131 | 131 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $payload = self::createPaymentPayload($user, $amount, $purpose, $phone); |
28 | 28 | |
29 | - $response = self::closeCurl($curl,$payload); |
|
29 | + $response = self::closeCurl($curl, $payload); |
|
30 | 30 | |
31 | 31 | $finalResponse = json_decode($response); |
32 | 32 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * To process the refund's |
60 | 60 | */ |
61 | 61 | |
62 | - public static function refund($payment_id,$type,$reason) |
|
62 | + public static function refund($payment_id, $type, $reason) |
|
63 | 63 | { |
64 | 64 | $sub = config('laravelmojo.subdomain_for_endpoints'); |
65 | 65 | |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | |
68 | 68 | $payload = ['payment_id' => $payment_id, |
69 | 69 | 'type' => $type, |
70 | - 'body' => $reason ]; |
|
70 | + 'body' => $reason]; |
|
71 | 71 | |
72 | - $response = self::closeCurl($curl,$payload); |
|
72 | + $response = self::closeCurl($curl, $payload); |
|
73 | 73 | $afterDecoding = json_decode($response); |
74 | 74 | $refund = $afterDecoding->refund; |
75 | 75 | |
76 | - $transaction = MojoPaymentDetails::where('payment_id',$payment_id)->first(); |
|
76 | + $transaction = MojoPaymentDetails::where('payment_id', $payment_id)->first(); |
|
77 | 77 | $user_id = $transaction->user_id; |
78 | 78 | |
79 | - $refund_record = self::createRefundInDB($user_id,$refund,$payment_id); |
|
79 | + $refund_record = self::createRefundInDB($user_id, $refund, $payment_id); |
|
80 | 80 | |
81 | 81 | return $refund_record; |
82 | 82 | } |
@@ -87,23 +87,23 @@ discard block |
||
87 | 87 | throw new Exception('Please set the Instamojo API key in your env file'); |
88 | 88 | } |
89 | 89 | |
90 | - elseif(!config('laravelmojo.token')) { |
|
90 | + elseif (!config('laravelmojo.token')) { |
|
91 | 91 | throw new Exception('Please set the Instamojo token in your env file'); |
92 | 92 | } |
93 | 93 | |
94 | - elseif(!config('laravelmojo.redirect_url_after_payment')) { |
|
94 | + elseif (!config('laravelmojo.redirect_url_after_payment')) { |
|
95 | 95 | throw new Exception('Please set the redirect url in your env file'); |
96 | 96 | } |
97 | 97 | |
98 | - elseif(!config('laravelmojo.subdomain_for_endpoints')) { |
|
98 | + elseif (!config('laravelmojo.subdomain_for_endpoints')) { |
|
99 | 99 | throw new Exception('Please set the subdomain for Instamojo api endpoint in your env file'); |
100 | 100 | } |
101 | 101 | |
102 | - elseif(!config('laravelmojo.webhook_url')) { |
|
102 | + elseif (!config('laravelmojo.webhook_url')) { |
|
103 | 103 | throw new Exception('Please set the webhook url in your env file'); |
104 | 104 | } |
105 | 105 | |
106 | - elseif(!config('laravelmojo.salt')) { |
|
106 | + elseif (!config('laravelmojo.salt')) { |
|
107 | 107 | throw new Exception('Please set the instamojo salt in your env file'); |
108 | 108 | } |
109 | 109 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | curl_setopt($ch, CURLOPT_HEADER, FALSE); |
125 | 125 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
126 | 126 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
127 | - curl_setopt($ch, CURLOPT_HTTPHEADER,["X-Api-Key:{$api_key}", |
|
127 | + curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Api-Key:{$api_key}", |
|
128 | 128 | "X-Auth-Token:{$api_token}"]); |
129 | 129 | return $ch; |
130 | 130 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - private static function closeCurl($curl,$payload) |
|
137 | + private static function closeCurl($curl, $payload) |
|
138 | 138 | { |
139 | 139 | curl_setopt($curl, CURLOPT_POST, true); |
140 | 140 | curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payload)); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | private static function createPaymentPayload(User $user, $amount, $purpose, $phone = null) |
148 | 148 | { |
149 | - if(is_null($phone)) { |
|
149 | + if (is_null($phone)) { |
|
150 | 150 | $phone = $user->phone; |
151 | 151 | } |
152 | 152 | |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | 'webhook' => config('laravelmojo.webhook_url'), |
160 | 160 | 'send_sms' => false, |
161 | 161 | 'email' => $user->email, |
162 | - 'allow_repeated_payments' => false ]; |
|
162 | + 'allow_repeated_payments' => false]; |
|
163 | 163 | |
164 | 164 | return $payload; |
165 | 165 | } |
166 | 166 | |
167 | - private static function createRefundInDB($user_id,$refund,$payment_id) |
|
167 | + private static function createRefundInDB($user_id, $refund, $payment_id) |
|
168 | 168 | { |
169 | 169 | $refund_record = MojoRefundDetails::create(['user_id' => $user_id, |
170 | 170 | 'refund_id' => $refund->id, |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | } |
186 | 186 | public static function allPaymentsFor(User $user) |
187 | 187 | { |
188 | - return MojoPaymentDetails::where('user_id',$user->id)->get(); |
|
188 | + return MojoPaymentDetails::where('user_id', $user->id)->get(); |
|
189 | 189 | } |
190 | 190 | public static function failedPayments() |
191 | 191 | { |
192 | - return MojoPaymentDetails::where('payment_status','!=','credit')->get(); |
|
192 | + return MojoPaymentDetails::where('payment_status', '!=', 'credit')->get(); |
|
193 | 193 | } |
194 | 194 | public static function successfulPayments() |
195 | 195 | { |
196 | - return MojoPaymentDetails::where('payment_status','credit')->get(); |
|
196 | + return MojoPaymentDetails::where('payment_status', 'credit')->get(); |
|
197 | 197 | } |
198 | 198 | public static function myAndMojosIncome() |
199 | 199 | { |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } |
217 | 217 | public static function allRefundsFor(User $user) |
218 | 218 | { |
219 | - return MojoRefundDetails::where('user_id',$user->id)->get(); |
|
219 | + return MojoRefundDetails::where('user_id', $user->id)->get(); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | } |
@@ -85,29 +85,17 @@ discard block |
||
85 | 85 | { |
86 | 86 | if (!config('laravelmojo.key')) { |
87 | 87 | throw new Exception('Please set the Instamojo API key in your env file'); |
88 | - } |
|
89 | - |
|
90 | - elseif(!config('laravelmojo.token')) { |
|
88 | + } elseif(!config('laravelmojo.token')) { |
|
91 | 89 | throw new Exception('Please set the Instamojo token in your env file'); |
92 | - } |
|
93 | - |
|
94 | - elseif(!config('laravelmojo.redirect_url_after_payment')) { |
|
90 | + } elseif(!config('laravelmojo.redirect_url_after_payment')) { |
|
95 | 91 | throw new Exception('Please set the redirect url in your env file'); |
96 | - } |
|
97 | - |
|
98 | - elseif(!config('laravelmojo.subdomain_for_endpoints')) { |
|
92 | + } elseif(!config('laravelmojo.subdomain_for_endpoints')) { |
|
99 | 93 | throw new Exception('Please set the subdomain for Instamojo api endpoint in your env file'); |
100 | - } |
|
101 | - |
|
102 | - elseif(!config('laravelmojo.webhook_url')) { |
|
94 | + } elseif(!config('laravelmojo.webhook_url')) { |
|
103 | 95 | throw new Exception('Please set the webhook url in your env file'); |
104 | - } |
|
105 | - |
|
106 | - elseif(!config('laravelmojo.salt')) { |
|
96 | + } elseif(!config('laravelmojo.salt')) { |
|
107 | 97 | throw new Exception('Please set the instamojo salt in your env file'); |
108 | - } |
|
109 | - |
|
110 | - else { |
|
98 | + } else { |
|
111 | 99 | return true; |
112 | 100 | } |
113 | 101 | } |
@@ -128,8 +116,7 @@ discard block |
||
128 | 116 | "X-Auth-Token:{$api_token}"]); |
129 | 117 | return $ch; |
130 | 118 | |
131 | - } |
|
132 | - else { |
|
119 | + } else { |
|
133 | 120 | throw new Exception('CURL extension is not loaded'); |
134 | 121 | } |
135 | 122 | } |
@@ -19,19 +19,19 @@ discard block |
||
19 | 19 | $major = (int) $ver[0]; |
20 | 20 | $minor = (int) $ver[1]; |
21 | 21 | if($major >= 5 and $minor >= 4){ |
22 | - ksort($data, SORT_STRING | SORT_FLAG_CASE); |
|
22 | + ksort($data, SORT_STRING | SORT_FLAG_CASE); |
|
23 | 23 | } |
24 | 24 | else{ |
25 | - uksort($data, 'strcasecmp'); |
|
25 | + uksort($data, 'strcasecmp'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $mac_calculated = hash_hmac("sha1", implode("|", $data), config('laravelmojo.salt')); |
29 | 29 | if($mac_provided == $mac_calculated){ |
30 | - if($data['status'] == "Credit"){ |
|
30 | + if($data['status'] == "Credit"){ |
|
31 | 31 | |
32 | - $user = User::where('email',$data['buyer'])->first(); |
|
32 | + $user = User::where('email',$data['buyer'])->first(); |
|
33 | 33 | $user_id = $user->id; |
34 | - MojoPaymentDetails::create(['user_id' => $user_id, |
|
34 | + MojoPaymentDetails::create(['user_id' => $user_id, |
|
35 | 35 | 'buyer_email' => $data['buyer'], |
36 | 36 | 'buyer_name' => $data['buyer_name'], |
37 | 37 | 'buyer_phone' => $data['buyer_phone'], |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | 'request_status' => 'completed', |
47 | 47 | 'payment_status' => $data['status'], |
48 | 48 | ]); |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - else{ |
|
51 | + else{ |
|
52 | 52 | |
53 | - $user = User::where('email',$data['buyer'])->first(); |
|
53 | + $user = User::where('email',$data['buyer'])->first(); |
|
54 | 54 | $user_id = $user->id; |
55 | - MojoPaymentDetails::create(['user_id' => $user_id, |
|
55 | + MojoPaymentDetails::create(['user_id' => $user_id, |
|
56 | 56 | 'buyer_email' => $data['buyer'], |
57 | 57 | 'buyer_name' => $data['buyer_name'], |
58 | 58 | 'buyer_phone' => $data['buyer_phone'], |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | 'payment_status' => $data['status'], |
69 | 69 | ]); |
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | else{ |
74 | - echo "MAC mismatch"; |
|
74 | + echo "MAC mismatch"; |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -18,18 +18,18 @@ discard block |
||
18 | 18 | $ver = explode('.', phpversion()); |
19 | 19 | $major = (int) $ver[0]; |
20 | 20 | $minor = (int) $ver[1]; |
21 | - if($major >= 5 and $minor >= 4){ |
|
21 | + if ($major >= 5 and $minor >= 4) { |
|
22 | 22 | ksort($data, SORT_STRING | SORT_FLAG_CASE); |
23 | 23 | } |
24 | - else{ |
|
24 | + else { |
|
25 | 25 | uksort($data, 'strcasecmp'); |
26 | 26 | } |
27 | 27 | |
28 | 28 | $mac_calculated = hash_hmac("sha1", implode("|", $data), config('laravelmojo.salt')); |
29 | - if($mac_provided == $mac_calculated){ |
|
30 | - if($data['status'] == "Credit"){ |
|
29 | + if ($mac_provided == $mac_calculated) { |
|
30 | + if ($data['status'] == "Credit") { |
|
31 | 31 | |
32 | - $user = User::where('email',$data['buyer'])->first(); |
|
32 | + $user = User::where('email', $data['buyer'])->first(); |
|
33 | 33 | $user_id = $user->id; |
34 | 34 | MojoPaymentDetails::create(['user_id' => $user_id, |
35 | 35 | 'buyer_email' => $data['buyer'], |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | ]); |
49 | 49 | } |
50 | 50 | |
51 | - else{ |
|
51 | + else { |
|
52 | 52 | |
53 | - $user = User::where('email',$data['buyer'])->first(); |
|
53 | + $user = User::where('email', $data['buyer'])->first(); |
|
54 | 54 | $user_id = $user->id; |
55 | 55 | MojoPaymentDetails::create(['user_id' => $user_id, |
56 | 56 | 'buyer_email' => $data['buyer'], |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | } |
72 | 72 | } |
73 | - else{ |
|
73 | + else { |
|
74 | 74 | echo "MAC mismatch"; |
75 | 75 | } |
76 | 76 | } |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | $minor = (int) $ver[1]; |
21 | 21 | if($major >= 5 and $minor >= 4){ |
22 | 22 | ksort($data, SORT_STRING | SORT_FLAG_CASE); |
23 | - } |
|
24 | - else{ |
|
23 | + } else{ |
|
25 | 24 | uksort($data, 'strcasecmp'); |
26 | 25 | } |
27 | 26 | |
@@ -46,9 +45,7 @@ discard block |
||
46 | 45 | 'request_status' => 'completed', |
47 | 46 | 'payment_status' => $data['status'], |
48 | 47 | ]); |
49 | - } |
|
50 | - |
|
51 | - else{ |
|
48 | + } else{ |
|
52 | 49 | |
53 | 50 | $user = User::where('email',$data['buyer'])->first(); |
54 | 51 | $user_id = $user->id; |
@@ -69,8 +66,7 @@ discard block |
||
69 | 66 | ]); |
70 | 67 | |
71 | 68 | } |
72 | - } |
|
73 | - else{ |
|
69 | + } else{ |
|
74 | 70 | echo "MAC mismatch"; |
75 | 71 | } |
76 | 72 | } |
@@ -8,14 +8,14 @@ |
||
8 | 8 | { |
9 | 9 | public function boot() |
10 | 10 | { |
11 | - $this->loadMigrationsFrom(__DIR__.'/../migrations'); |
|
11 | + $this->loadMigrationsFrom(__DIR__.'/../migrations'); |
|
12 | 12 | |
13 | - $this->publishes([ |
|
14 | - __DIR__.'/config/laravelmojo.php' => config_path('laravelmojo.php'), |
|
15 | - ]); |
|
13 | + $this->publishes([ |
|
14 | + __DIR__.'/config/laravelmojo.php' => config_path('laravelmojo.php'), |
|
15 | + ]); |
|
16 | 16 | } |
17 | - public function register() |
|
18 | - { |
|
17 | + public function register() |
|
18 | + { |
|
19 | 19 | |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -8,10 +8,10 @@ |
||
8 | 8 | { |
9 | 9 | public function boot() |
10 | 10 | { |
11 | - $this->loadMigrationsFrom(__DIR__.'/../migrations'); |
|
11 | + $this->loadMigrationsFrom(__DIR__ . '/../migrations'); |
|
12 | 12 | |
13 | 13 | $this->publishes([ |
14 | - __DIR__.'/config/laravelmojo.php' => config_path('laravelmojo.php'), |
|
14 | + __DIR__ . '/config/laravelmojo.php' => config_path('laravelmojo.php'), |
|
15 | 15 | ]); |
16 | 16 | } |
17 | 17 | public function register() |
@@ -2,24 +2,24 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | * Specify the Private AUTH KEY in your .env file provided |
7 | 7 | * by Instamojo in the API & Plugin's section |
8 | 8 | * of your account's integration page. |
9 | 9 | */ |
10 | 10 | |
11 | - 'key' => env('INSTAMOJO_KEY', null), |
|
11 | + 'key' => env('INSTAMOJO_KEY', null), |
|
12 | 12 | |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * Specify your Private AUTH TOKEN in your .env file provided by Instamojo in the |
15 | 15 | * API & Plugins section of your integration page. |
16 | 16 | * Also I haven't watched a single episode of FRIENDS yet, please |
17 | 17 | * don't judge me for that. It's on my list. |
18 | 18 | */ |
19 | 19 | |
20 | - 'token' => env('INSTAMOJO_TOKEN', null), |
|
20 | + 'token' => env('INSTAMOJO_TOKEN', null), |
|
21 | 21 | |
22 | - /* |
|
22 | + /* |
|
23 | 23 | * The URL of your app to which the user will be redirected after the |
24 | 24 | * payment process at Instamojo's part will end. |
25 | 25 | * Tip : If you are testing on localhost , create a alias in your host |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | * as your base URL. And add it to your routes. |
28 | 28 | */ |
29 | 29 | |
30 | - 'redirect_url_after_payment' => env('INSTAMOJO_REDIRECT_URL', null), |
|
30 | + 'redirect_url_after_payment' => env('INSTAMOJO_REDIRECT_URL', null), |
|
31 | 31 | |
32 | - /* |
|
32 | + /* |
|
33 | 33 | * These took me an hour to figure out , for testing purposers you will |
34 | 34 | * most probably use the instamojo sandbox testing account , if thats |
35 | 35 | * the case, then the subdomain for all your endpoints will be "test" |
@@ -38,23 +38,23 @@ discard block |
||
38 | 38 | * then it will be "www" |
39 | 39 | */ |
40 | 40 | |
41 | - 'subdomain_for_endpoints' => env('INSTAMOJO_SUBDOMAIN', null), |
|
41 | + 'subdomain_for_endpoints' => env('INSTAMOJO_SUBDOMAIN', null), |
|
42 | 42 | |
43 | - /* |
|
43 | + /* |
|
44 | 44 | * WEBHOOK is your app's URL to which Instamojo sends |
45 | 45 | * payment details as a POST request. This package |
46 | 46 | * handles everything , you just have to define |
47 | 47 | * the POST route & add it your route's file |
48 | 48 | */ |
49 | 49 | |
50 | - 'webhook_url' => env('INSTAMOJO_WEBHOOK_URL', null), |
|
50 | + 'webhook_url' => env('INSTAMOJO_WEBHOOK_URL', null), |
|
51 | 51 | |
52 | - /* |
|
52 | + /* |
|
53 | 53 | * Specify the Private SALT in your .env file provided |
54 | 54 | * by Instamojo in the API & Plugin's section |
55 | 55 | * of your account's integration page. |
56 | 56 | */ |
57 | 57 | |
58 | - 'salt' => env('INSTAMOJO_SALT', null), |
|
58 | + 'salt' => env('INSTAMOJO_SALT', null), |
|
59 | 59 | |
60 | 60 | ]; |