/** * @override */ public function StartCheckout(IShopOrder $order, $ok_url = false, $cancel_url = false) { global $CONFIG; if (!$ok_url) { WdfException::Raise('PayPal needs a return URL'); } if (!$cancel_url) { $cancel_url = $ok_url; } $invoice_id = false; if ($tmp = $order->GetInvoiceId()) { $invoice_id = $tmp; } $this->SetVar("cmd", "_cart"); $this->SetVar("upload", "1"); $order_currency = $this->EnsureCurrency($order); $order->SetCurrency($order_currency); $this->SetVar("currency_code", $order_currency); $this->SetVar("charset", "utf-8"); // set language of paypal UI: // $this->SetVar("lc", ); if ($CONFIG["payment"]["paypal"]["use_sandbox"] == true) { $this->SetVar("sandbox", "1"); $checkoutUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } else { $checkoutUrl = "https://www.paypal.com/cgi-bin/webscr"; } $this->SetVar('business', $CONFIG["payment"]["paypal"]["paypal_id"]); $this->SetVar('custom', $CONFIG["payment"]["paypal"]["custom"]); if ($invoice_id) { $ok_url .= (stripos($ok_url, '?') !== false ? '&' : '?') . "order_id={$invoice_id}"; $cancel_url .= (stripos($cancel_url, '?') !== false ? '&' : '?') . "order_id={$invoice_id}"; } $this->SetVar('return', $ok_url); $this->SetVar('cancel_return', $cancel_url); $params = array("provider" => "paypal"); $notify_url = buildQuery($CONFIG["payment"]["paypal"]["notify_handler"][0], $CONFIG["payment"]["paypal"]["notify_handler"][1], $params); $this->SetVar('notify_url', $notify_url); // customer details $address = $order->GetAddress(); if ($address->Firstname) { $this->SetVar('first_name', $address->Firstname); } if ($address->Lastname) { $this->SetVar('last_name', $address->Lastname); } if ($address->Email) { $this->SetVar('email', $address->Email); } if ($address->Address1) { $this->SetVar('address1', $address->Address1); } if ($address->Address2) { $this->SetVar('address2', $address->Address2); } if ($address->Country) { $this->SetVar('country', $address->Country); } if ($address->State) { $this->SetVar('state', $address->State); } if ($address->Zip) { $this->SetVar('zip', $address->Zip); } if ($address->City) { $this->SetVar('city', $address->City); } // tell paypal to use this entered address: $this->SetVar('address_override', 1); $this->SetVar('bn', $CONFIG["payment"]["paypal"]["custom"]); // do not let users add notes in paypal: $this->SetVar('no_note', 1); /* Return method. The FORM METHOD used to send data to the URL specified by the return variable. Allowable values are: 0 – all shopping cart payments use the GET method 1 – the buyer’s browser is re directed to the return URL by using the GET method, but no payment variables are included 2 – the buyer’s browser is re directed to the return URL by using the POST method, and all payment variables are included */ $this->SetVar('rm', 1); if ($invoice_id) { $this->SetVar('invoice', $invoice_id); } $items = $order->ListItems(); if (count($items) > 0) { $i = 1; foreach ($items as $item) { $price = $item->GetAmount(); $this->SetVar("item_name_{$i}", $item->GetName()); $this->SetVar("amount_{$i}", round($item->GetAmount($order_currency), 2)); if ($order->DoAddVat()) { $this->SetVar("tax_{$i}", round($item->GetAmount($order_currency) * ($CONFIG['model']['vat_percent'] / 100), 2)); } $this->SetVar("quantity_{$i}", 1); $i++; } } $this->SetVar("tax_cart", round($order->GetTotalVat(), 2)); return $this->CheckoutForm($checkoutUrl); }
private function HandlePayment(IShopOrder $order, $ipndata) { $payment_status = strtolower($ipndata["ppp_status"]); $transaction_id = $ipndata["TransactionID"]; $statusmsg = false; if (strval($ipndata["ErrCode"]) == '0' && strval($ipndata["ExErrCode"]) == '-2') { $payment_status = "pending"; $statusmsg = "Your order will be reviewed manually"; } elseif (strval($ipndata["ErrCode"]) != '0' || strval($ipndata["ExErrCode"]) != '0' || $ipndata["ppp_status"] == "FAIL") { if (isset($ipndata["Error"]) && strlen($ipndata["Error"])) { $statusmsg = "ErrCode: " . $ipndata["ErrCode"] . ", ExErrCode: " . $ipndata["ExErrCode"] . " " . $ipndata["Reason"] . ", " . $ipndata["Error"]; } else { $statusmsg = "ErrCode: " . $ipndata["ErrCode"] . ", ExErrCode: " . $ipndata["ExErrCode"] . ", " . "Your transaction has been declined."; } $payment_status = "failed"; } if (isset($ipndata["transactionType"]) && ($ipndata["transactionType"] == "Credit" || $ipndata["transactionType"] == "ChargeBack" || $ipndata["transactionType"] == "Void" || $ipndata["transactionType"] == "Modification" && $ipndata["Status"] == "CANCELED")) { $payment_status = "refunded"; } switch ($payment_status) { case "pending": $order->SetPending(PaymentProvider::PROCESSOR_GATE2SHOP, $transaction_id, $statusmsg); break; case "ok": $order->SetPaid(PaymentProvider::PROCESSOR_GATE2SHOP, $transaction_id, $statusmsg); break; case "failed": $order->SetFailed(PaymentProvider::PROCESSOR_GATE2SHOP, $transaction_id, $statusmsg); break; case "refunded": $order->SetRefunded(PaymentProvider::PROCESSOR_GATE2SHOP, $transaction_id, $statusmsg); break; default: return "Unkown payment status: {$payment_status}"; break; } return true; }