Skip to content

Commit

Permalink
Fix paypal status and type
Browse files Browse the repository at this point in the history
  • Loading branch information
joecohens committed Oct 11, 2017
1 parent 258bd3c commit 21d5b5c
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/Gateways/PaypalExpress/PaypalExpressGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,20 @@ public function mapResponse($success, $response)
'isRedirect' => false,
'success' => $success ? true : false,
'reference' => $success ? Arr::get($response, 'invoice') : false,
'message' => $success ? 'Transaction approved' : 'Transaction failed',
'message' => $success ? 'VERIFIED' : 'INVALID',
'test' => $this->config['test'],
'authorization' => $success ? Arr::get($response, 'txn_id') : '',
'status' => $success ? new Status('paid') : new Status('failed'),
'status' => $success ? $this->getPaymentStatus($response) : new Status('failed'),
'errorCode' => null,
'type' => $success ? Arr::get($response, 'payment_status') : null,
'type' => $success ? Arr::get($response, 'txn_type') : null,
]);
}

return (new Response())->setRaw($rawResponse)->map([
'isRedirect' => $response['isRedirect'],
'success' => $response['isRedirect'] ? false : $success,
'reference' => $success ? $this->getReference($response, $response['isRedirect']) : false,
'message' => $success ? 'Transaction approved' : $response['L_LONGMESSAGE0'],
'message' => $success ? Arr::get($response, 'ACK', 'Transaction approved') : $response['L_LONGMESSAGE0'],
'test' => $this->config['test'],
'authorization' => $this->getAuthorization($response, $success, $response['isRedirect']),
'status' => $success ? $this->getStatus($response, $response['isRedirect']) : new Status('failed'),
Expand Down Expand Up @@ -311,6 +311,40 @@ protected function getStatus($response, $isRedirect)
return new Status('paid');
}

/**
* Map PayPal payment response to status object.
*
* @param array $response
*
* @return \Shoperti\PayMe\Status
*/
protected function getPaymentStatus($response)
{
switch ($status = Arr::get($response, 'payment_status', 'paid')) {
case 'Completed':
case 'Processed':
return new Status('paid');
case 'Created':
case 'Pending':
return new Status('pending');
case 'Canceled_Reversal':
return new Status('canceled');
case 'Failed':
case 'Denied':
return new Status('failed');
case 'Declined':
return new Status('declined');
case 'Expired':
return new Status('expired');
case 'Refunded':
return new Status('refunded');
case 'Reversed':
return new Status('charged_back');
case 'Voided':
return new Status('voided');
}
}

/**
* Map PayPalExpress response to error code object.
*
Expand Down

0 comments on commit 21d5b5c

Please sign in to comment.