Skip to content

Commit 5b78214

Browse files
committed
Updated Paypal Service to Throw Error is Auth is Missing
1 parent a8461b3 commit 5b78214

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function cartComplete(Request $request, $proc){
178178
try{
179179
$result = $processor->pdt($request->all());
180180
}catch(TransactionException $exception){
181-
Log::error($exception->getMessage(), $exception->getData());
181+
Log::error($exception->getMessage());
182182
}
183183

184184
if(!empty($result)){
@@ -202,7 +202,7 @@ public function handleIpn(Request $request, $proc){
202202
$result = $processor->ipn($request->all());
203203
}catch(Userdesk\Subscription\Exceptions\TransactionException $exception){
204204
//Handle Exceptions
205-
Log::error($exception->getMessage(), $exception->getData());
205+
Log::error($exception->getMessage());
206206
}
207207

208208
if(!empty($result)){

src/Services/Paypal.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ public function ipn(array $input){
117117
public function pdt(array $input){
118118
$req = 'cmd=_notify-synch';
119119
$tx_token = array_get($input, 'tx');
120-
$auth_token = array_get($this->config, 'auth');#'AHzOaZtWjQ7yNtBokHmpmrVfnpahZtiD3pr5HeKAiw9a_wxzPON14erlCDe';#
120+
$auth_token = array_get($this->config, 'auth');
121+
122+
if(empty($auth_token)){
123+
throw new TransactionException('Invalid Paypal Auth Token');
124+
}
125+
121126
$req .= "&tx=$tx_token&at=$auth_token";
122127

123128
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
124129
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
125130
$header .= "Content-Length: ".strlen ($req)."\r\n\r\n";
126131
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
132+
127133

128134
if (!$fp) {
129-
throw new TransactionException('Cannot Connect to Paypal', ['data'=>$input]);
135+
throw new TransactionException('Cannot Connect to Paypal');
130136
} else {
131137
fputs ($fp, $header.$req);
132138
$res = '';
@@ -148,7 +154,7 @@ public function pdt(array $input){
148154

149155
$keys = collect([]);
150156

151-
if (strcmp ($lines[0], "SUCCESS") == 0) {
157+
if (strcmp ($lines[0], "SUCCESS") == 0) {
152158
for ($i = 1; $i < count ($lines); $i++) {
153159
@list ($key, $val) = explode ("=", $lines[$i]);
154160
$keys->put(urldecode($key), urldecode ($val));
@@ -169,9 +175,9 @@ public function pdt(array $input){
169175
$action = 'signup';
170176
}
171177

172-
return new TransactionResult($item_number, $subscr_id, 0, $payment_status, $action, $keys->get());
178+
return new TransactionResult($item_number, $subscr_id, 0, $payment_status, $action, $keys->get());
173179
} elseif (strcmp ($lines[0], "FAIL") == 0) {
174-
throw new TransactionException("Paypal check failed", ['lines'=>$lines, 'keys'=>$keys]);
180+
throw new TransactionException("Paypal check failed");
175181
}
176182
}
177183
}

0 commit comments

Comments
 (0)