コード例 #1
0
ファイル: notifier.php プロジェクト: Evil1991/PrestaShop-1.4
 public function confirmOrder($custom)
 {
     $cart = new Cart((int) $custom['id_cart']);
     $cart_details = $cart->getSummaryDetails(null, true);
     $cart_hash = sha1(serialize($cart->nbProducts()));
     $this->context->cart = $cart;
     $address = new Address((int) $cart->id_address_invoice);
     $this->context->country = new Country((int) $address->id_country);
     $this->context->customer = new Customer((int) $cart->id_customer);
     $this->context->language = new Language((int) $cart->id_lang);
     $this->context->currency = new Currency((int) $cart->id_currency);
     if (isset($cart->id_shop)) {
         $this->context->shop = new Shop($cart->id_shop);
     }
     $res = $this->getResult();
     if (strcmp($res, "VERIFIED") == 0) {
         $currency_decimals = is_array($this->context->currency) ? (int) $this->context->currency['decimals'] : (int) $this->context->currency->decimals;
         $this->decimals = $currency_decimals * _PS_PRICE_DISPLAY_PRECISION_;
         $message = null;
         $mc_gross = Tools::ps_round(Tools::getValue('mc_gross'), $this->decimals);
         $cart_details = $cart->getSummaryDetails(null, true);
         $shipping = $cart_details['total_shipping_tax_exc'];
         $subtotal = $cart_details['total_price_without_tax'] - $cart_details['total_shipping_tax_exc'];
         $tax = $cart_details['total_tax'];
         $total_price = Tools::ps_round($shipping + $subtotal + $tax, $this->decimals);
         if (bccomp($mc_gross, $total_price, 2) !== 0) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Price paid on paypal is not the same that on PrestaShop.') . '<br />';
         } elseif ($custom['hash'] != $cart_hash) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Cart changed, please retry.') . '<br />';
         } else {
             $payment = (int) Configuration::get('PS_OS_PAYMENT');
             $message = $this->l('Payment accepted.') . '<br />';
         }
         $customer = new Customer((int) $cart->id_customer);
         $transaction = PayPalOrder::getTransactionDetails(false);
         if (_PS_VERSION_ < '1.5') {
             $shop = null;
         } else {
             $shop_id = $this->context->shop->id;
             $shop = new Shop($shop_id);
         }
         $this->validateOrder($cart->id, $payment, $total_price, $this->displayName, $message, $transaction, $cart->id_currency, false, $customer->secure_key, $shop);
     }
 }
コード例 #2
0
ファイル: payment.php プロジェクト: ventsiwad/presta_addons
/**
 * Check payment return
 */
function validateOrder($customer, $cart, $ppec)
{
    $amount_match = $ppec->rightPaymentProcess();
    $order_total = (double) $cart->getOrderTotal(true, Cart::BOTH);
    // Payment succeed
    if ($ppec->hasSucceedRequest() && !empty($ppec->token) && $amount_match) {
        if ((bool) Configuration::get('PAYPAL_CAPTURE')) {
            $payment_type = (int) Configuration::get('PS_OS_WS_PAYMENT');
            $payment_status = 'Pending_capture';
            $message = $ppec->l('Pending payment capture.') . '<br />';
        } else {
            if (isset($ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'])) {
                $payment_status = $ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'];
            } else {
                $payment_status = 'Error';
            }
            if (strcmp($payment_status, 'Completed') === 0) {
                $payment_type = (int) Configuration::get('PS_OS_PAYMENT');
                $message = $ppec->l('Payment accepted.') . '<br />';
            } elseif (strcmp($payment_status, 'Pending') === 0) {
                $payment_type = (int) Configuration::get('PS_OS_PAYPAL');
                $message = $ppec->l('Pending payment confirmation.') . '<br />';
            }
        }
    } else {
        //Check if error is 10486, if it is redirect user to paypal
        if ($ppec->result['L_ERRORCODE0'] == 10486) {
            $ppec->redirectToAPI();
        }
        $payment_status = $ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'];
        $payment_type = (int) Configuration::get('PS_OS_ERROR');
        if ($amount_match) {
            $message = implode('<br />', $ppec->logs) . '<br />';
        } else {
            $message = $ppec->l('Price paid on paypal is not the same that on PrestaShop.') . '<br />';
        }
    }
    $transaction = PayPalOrder::getTransactionDetails($ppec, $payment_status);
    $ppec->context->cookie->id_cart = $cart->id;
    $ppec->validateOrder((int) $cart->id, $payment_type, $order_total, $ppec->displayName, $message, $transaction, (int) $cart->id_currency, false, $customer->secure_key, $ppec->context->shop);
}