Example #1
0
 public function loadFromCart(Cart $cart)
 {
     $shopInfo = new ShopInfo($cart->module_srl);
     $this->cart_srl = $cart->cart_srl;
     $this->module_srl = $cart->module_srl;
     $this->member_srl = $cart->member_srl;
     $this->client_name = $cart->getBillingAddress()->firstname . ' ' . $cart->getBillingAddress()->lastname;
     $this->client_email = $cart->getBillingAddress()->email;
     $this->client_company = $cart->getBillingAddress()->company;
     $this->billing_address = (string) $cart->getBillingAddress();
     $this->shipping_address = (string) $cart->getShippingAddress();
     $this->payment_method = $cart->getPaymentMethodName();
     $this->shipping_method = $cart->getShippingMethodName();
     $this->shipping_variant = $cart->getShippingMethodVariant();
     $this->shipping_cost = $cart->getShippingCost();
     $this->total = $cart->getTotal(true);
     $this->vat = $shopInfo->getVAT() ? $shopInfo->getVAT() : 0;
     $this->order_status = Order::ORDER_STATUS_PENDING;
     $this->ip = $_SERVER['REMOTE_ADDR'];
     $this->currency = $shopInfo->getCurrency();
     if ($discount = $cart->getDiscount()) {
         $this->discount_min_order = $discount->getMinValueForDiscount();
         $this->discount_type = $shopInfo->getShopDiscountType();
         $this->discount_amount = $discount->getReductionValue();
         $this->discount_tax_phase = $discount->calculateBeforeApplyingVAT() ? 'pre_taxes' : 'post_taxes';
         $this->discount_reduction_value = $discount->getReductionValue();
     }
     if ($coupon = $cart->getCoupon()) {
         $this->coupon_discount_value = $cart->getCouponDiscount();
     }
 }
	/**
	 * Calls the Paypal API for executing the payment
	 *
	 * @param Cart $cart
	 * @param      $error_message
	 * @return bool|mixed
	 */
	public function processPayment(Cart $cart, &$error_message)
    {
        $payer_id = Context::get('payer_id');
        $token = Context::get('token');

        $paypalAPI = new PaypalExpressCheckoutAPI($this->gateway_api == PaypalExpressCheckout::LIVE_URL
			, $this->api_username
            , $this->api_password
            , $this->signature
        );

        // Get shop info
        $shop_info = new ShopInfo($cart->module_srl);

        // Prepare cart info
        $items = $this->getItemsFromCart($cart);

        $paypalAPI->doExpressCheckoutPayment($token
            , $payer_id
            , $items
            , ShopDisplay::numberFormat($cart->getItemTotal())
            , 0
            , ShopDisplay::numberFormat($cart->getShippingCost())
            , ShopDisplay::numberFormat($cart->getTotal())
            , $shop_info->getCurrency()
        );

        if(!$paypalAPI->success)
        {
            $error_message = $paypalAPI->error_message;
            return FALSE;
        }
        else
        {
            Context::set('payment_status', $paypalAPI->payment_status);
            return TRUE;
        }
    }
Example #3
0
 public function getCurrency()
 {
     $shop = new ShopInfo($this->module_srl);
     return $shop->getCurrency();
 }