Guest User

Untitled

a guest
Jan 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Get the payment and the corresponding merchant_order reported by the IPN.
  2. if($_GET["topic"] == 'payment'){
  3. $payment_info = $mp->get("/collections/notifications/" . $_GET["id"]);
  4. $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"]);
  5. // Get the merchant_order reported by the IPN.
  6. } else if($_GET["topic"] == 'merchant_order'){
  7. $merchant_order_info = $mp->get("/merchant_orders/" . $_GET["id"]);
  8. }
  9.  
  10. if ($merchant_order_info["status"] == 200) {
  11. // If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items
  12. $paid_amount = 0;
  13.  
  14. foreach ($merchant_order_info["response"]["payments"] as $payment) {
  15. if ($payment['status'] == 'approved'){
  16. $paid_amount += $payment['transaction_amount'];
  17. }
  18. }
  19.  
  20. if($paid_amount >= $merchant_order_info["response"]["total_amount"]){
  21. if(count($merchant_order_info["response"]["shipments"]) > 0) { // The merchant_order has shipments
  22. if($merchant_order_info["response"]["shipments"][0]["status"] == "ready_to_ship"){
  23. print_r("Totally paid. Print the label and release your item.");
  24. }
  25. } else { // The merchant_order don't has any shipments
  26. print_r("Totally paid. Release your item.");
  27. }
  28. } else {
  29. print_r("Not paid yet. Do not release your item.");
  30. }
Add Comment
Please, Sign In to add comment