Skip to content

Commit

Permalink
Merge pull request #96 from Shoperti/analysis-Xp5r6o
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
joecohens authored Oct 11, 2017
2 parents 21d5b5c + 66d046e commit faac016
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Gateways/MercadoPagoBasic/Charges.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function addPaymentMethod(array $params, $payment, array $options)
$paymentTypes = ['prepaid_card', 'digital_currency', 'credit_card', 'debit_card', 'ticket', 'atm', 'bank_transfer'];
$enabledTypes = Arr::get($options, 'enabled_brands', []);

$excludedTypes = array_map(function($type) {
$excludedTypes = array_map(function ($type) {
return ['id' => $type];
}, array_values(array_filter($paymentTypes, function ($type) use ($enabledTypes) {
return !in_array($type, $enabledTypes);
Expand Down
38 changes: 19 additions & 19 deletions src/Gateways/MercadoPagoBasic/MercadoPagoBasicGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public function mapResponse($success, $response)
'errorCode' => $success ? null : $this->getErrorCode($response),
'type' => null,
]);
}
}

return (new Response())->setRaw($rawResponse)->map([
'isRedirect' => false,
'success' => $success,
'reference' => $success ? $this->getReference($response) : null,
'message' => $success ? 'Transaction approved' : null,
'test' => $this->config['test'],
'authorization' => $success ?Arr::get($response, 'id') : null,
'authorization' => $success ? Arr::get($response, 'id') : null,
'status' => $success ? $this->getStatus($response) : new Status('failed'),
'errorCode' => $success ? null : $this->getErrorCode($response),
'type' => Arr::get($response, 'topic'),
Expand All @@ -180,7 +180,7 @@ public function mapResponse($success, $response)
* Get MercadoPago authorization.
*
* @param array $response
*
*
* @return string|null
*/
protected function getReference(array $response)
Expand All @@ -190,7 +190,7 @@ protected function getReference(array $response)
if (!$payments) {
return Arr::get($response, 'preference_id');
}

$lastPayment = end($payments);

return Arr::get($lastPayment, 'id');
Expand All @@ -216,23 +216,23 @@ protected function getStatus(array $response)
if (count($payments) > 1) {
$totalPaid = 0;
$totalRefund = 0;
$total = $newResponse['shipping_cost'] + $newResponse['total_amount'];
$total = $newResponse['shipping_cost'] + $newResponse['total_amount'];

foreach ($payments as $payment) {
if ($payment['status'] === 'approved') {
// Get the total paid amount, considering only approved incomings.
$totalPaid += $payment['total_paid_amount'] - $payment['amount_refunded'];
} elseif ($payment['status'] === 'refunded') {
// Get the total refunded amount.
$totalRefund += $payment['amount_refunded'];
}
if ($payment['status'] === 'approved') {
// Get the total paid amount, considering only approved incomings.
$totalPaid += $payment['total_paid_amount'] - $payment['amount_refunded'];
} elseif ($payment['status'] === 'refunded') {
// Get the total refunded amount.
$totalRefund += $payment['amount_refunded'];
}
}
if ($totalPaid >= $total) {
$newResponse['status'] = 'approved';
} elseif ($totalRefund >= $total) {
$newResponse['status'] = 'refunded';
} elseif ($totalRefund > 0) {

if ($totalPaid >= $total) {
$newResponse['status'] = 'approved';
} elseif ($totalRefund >= $total) {
$newResponse['status'] = 'refunded';
} elseif ($totalRefund > 0) {
$newResponse['status'] = 'partially_refunded';
} else {
$newResponse['status'] = 'pending';
Expand All @@ -242,7 +242,7 @@ protected function getStatus(array $response)
}

$newResponse['status'] = $payments[0]['amount_refunded'] > 0 ? 'partially_refunded' : $payments[0]['status'];

return parent::getStatus($newResponse);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/PaypalExpress/PaypalExpressGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ protected function getPaymentStatus($response)
case 'Processed':
return new Status('paid');
case 'Created':
case 'Pending':
case 'Pending':
return new Status('pending');
case 'Canceled_Reversal':
return new Status('canceled');
Expand Down

0 comments on commit faac016

Please sign in to comment.