Created
December 11, 2018 23:13
-
-
Save fgilio/3d6438b61d63578da39c7879458d29dd to your computer and use it in GitHub Desktop.
Revisions
-
fgilio created this gist
Dec 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <?php /* * Keep in mind that this is heavily tied to the Laravel Framework * * $client_id * $client_secret * $externalReference */ MercadoPago\SDK::setClientId($client_id); MercadoPago\SDK::setClientSecret($client_secret); $paymentService = new MercadoPago\Payment(); $payments = collect($paymentService->search(['external_reference' => $externalReference])); if ($payments->isEmpty()) { // No payments attempt made return; } $merchantOrder = MercadoPago\MerchantOrder::find_by_id($payments->first()->order->id); $paidAmount = collect($merchantOrder->payments) ->filter(function ($payment) { return $payment->status === 'approved'; }) ->sum('transaction_amount'); // If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items if ($paidAmount >= $merchantOrder->total_amount) { // Fully paid! } else { // Not paid yet }