예제 #1
0
파일: Standard.php 프로젝트: aiesh/magento2
 /**
  * Return form field array
  *
  * @return array
  */
 public function getStandardCheckoutFormFields()
 {
     $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
     /* @var $api \Magento\Paypal\Model\Api\Standard */
     $api = $this->_apiStandardFactory->create()->setConfigObject($this->getConfig());
     $api->setOrderId($orderIncrementId)->setCurrencyCode($order->getBaseCurrencyCode())->setOrder($order)->setNotifyUrl($this->_urlBuilder->getUrl('paypal/ipn/'))->setReturnUrl($this->_urlBuilder->getUrl('paypal/standard/success'))->setCancelUrl($this->_urlBuilder->getUrl('paypal/standard/cancel'));
     // export address
     $isOrderVirtual = $order->getIsVirtual();
     $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
     if ($isOrderVirtual) {
         $api->setNoShipping(true);
     } elseif ($address->validate()) {
         $api->setAddress($address);
     }
     // add cart totals and line items
     $cart = $this->_cartFactory->create(array('salesModel' => $order));
     $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_config->getConfigValue('lineItemsEnabled'));
     $api->setCartSummary($this->_getAggregatedCartSummary());
     $api->setLocale($api->getLocaleCode());
     $result = $api->getStandardCheckoutRequest();
     return $result;
 }
예제 #2
0
 /**
  * Place an order with authorization or capture action
  *
  * @param Payment $payment
  * @param float $amount
  * @return $this
  */
 protected function _placeOrder(Payment $payment, $amount)
 {
     $order = $payment->getOrder();
     /** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
     $billingAgreement = $this->_agreementFactory->create()->load($payment->getAdditionalInformation(\Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID));
     $cart = $this->_cartFactory->create(array('salesModel' => $order));
     $proConfig = $this->_pro->getConfig();
     $api = $this->_pro->getApi()->setReferenceId($billingAgreement->getReferenceId())->setPaymentAction($proConfig->getConfigValue('paymentAction'))->setAmount($amount)->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode())->setNotifyUrl($this->_urlBuilder->getUrl('paypal/ipn/'))->setPaypalCart($cart)->setIsLineItemsEnabled($proConfig->getConfigValue('lineItemsEnabled'))->setInvNum($order->getIncrementId());
     // call api and import transaction and other payment information
     $api->callDoReferenceTransaction();
     $this->_pro->importPaymentInfo($api, $payment);
     $api->callGetTransactionDetails();
     $this->_pro->importPaymentInfo($api, $payment);
     $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(0);
     if ($api->getBillingAgreementId()) {
         $order->addRelatedObject($billingAgreement);
         $billingAgreement->setIsObjectChanged(true);
         $billingAgreement->addOrderRelation($order);
     }
     return $this;
 }
예제 #3
0
파일: Direct.php 프로젝트: aiesh/magento2
 /**
  * Place an order with authorization or capture action
  *
  * @param Payment $payment
  * @param float $amount
  * @return $this
  */
 protected function _placeOrder(Payment $payment, $amount)
 {
     $order = $payment->getOrder();
     $api = $this->_pro->getApi()->setPaymentAction($this->_pro->getConfig()->getConfigValue('paymentAction'))->setIpAddress($this->_requestHttp->getClientIp(false))->setAmount($amount)->setCurrencyCode($order->getBaseCurrencyCode())->setInvNum($order->getIncrementId())->setEmail($order->getCustomerEmail())->setNotifyUrl($this->_urlBuilder->getUrl('paypal/ipn/'))->setCreditCardType($payment->getCcType())->setCreditCardNumber($payment->getCcNumber())->setCreditCardExpirationDate($this->_getFormattedCcExpirationDate($payment->getCcExpMonth(), $payment->getCcExpYear()))->setCreditCardCvv2($payment->getCcCid())->setMaestroSoloIssueNumber($payment->getCcSsIssue());
     if ($payment->getCcSsStartMonth() && $payment->getCcSsStartYear()) {
         $year = sprintf('%02d', substr($payment->getCcSsStartYear(), -2, 2));
         $api->setMaestroSoloIssueDate($this->_getFormattedCcExpirationDate($payment->getCcSsStartMonth(), $year));
     }
     if ($this->getIsCentinelValidationEnabled()) {
         $this->getCentinelValidator()->exportCmpiData($api);
     }
     // add shipping and billing addresses
     if ($order->getIsVirtual()) {
         $api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
     } else {
         $api->setAddress($order->getShippingAddress());
         $api->setBillingAddress($order->getBillingAddress());
     }
     // add line items
     $cart = $this->_cartFactory->create(array('salesModel' => $order));
     $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_pro->getConfig()->getConfigValue('lineItemsEnabled'));
     // call api and import transaction and other payment information
     $api->callDoDirectPayment();
     $this->_importResultToPayment($api, $payment);
     try {
         $api->callGetTransactionDetails();
     } catch (\Magento\Framework\Model\Exception $e) {
         // if we receive errors, but DoDirectPayment response is Success, then set Pending status for transaction
         $payment->setIsTransactionPending(true);
     }
     $this->_importResultToPayment($api, $payment);
     return $this;
 }
예제 #4
0
 /**
  * Reserve order ID for specified quote and start checkout on PayPal
  *
  * @param string $returnUrl
  * @param string $cancelUrl
  * @param bool|null $button
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function start($returnUrl, $cancelUrl, $button = null)
 {
     $this->_quote->collectTotals();
     if (!$this->_quote->getGrandTotal()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('PayPal can\'t process orders with a zero balance due. ' . 'To finish your purchase, please go through the standard checkout process.'));
     }
     $this->_quote->reserveOrderId();
     $this->quoteRepository->save($this->_quote);
     // prepare API
     $this->_getApi();
     $solutionType = $this->_config->getMerchantCountry() == 'DE' ? \Magento\Paypal\Model\Config::EC_SOLUTION_TYPE_MARK : $this->_config->getValue('solutionType');
     $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($solutionType)->setPaymentAction($this->_config->getValue('paymentAction'));
     if ($this->_giropayUrls) {
         list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
         $this->_api->addData(['giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl]);
     }
     if ($this->_isBml) {
         $this->_api->setFundingSource('BML');
     }
     $this->_setBillingAgreementRequest();
     if ($this->_config->getValue('requireBillingAddress') == PaypalConfig::REQUIRE_BILLING_ADDRESS_ALL) {
         $this->_api->setRequireBillingAddress(1);
     }
     // suppress or export shipping address
     $address = null;
     if ($this->_quote->getIsVirtual()) {
         if ($this->_config->getValue('requireBillingAddress') == PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL) {
             $this->_api->setRequireBillingAddress(1);
         }
         $this->_api->setSuppressShipping(true);
     } else {
         $address = $this->_quote->getShippingAddress();
         $isOverridden = 0;
         if (true === $address->validate()) {
             $isOverridden = 1;
             $this->_api->setAddress($address);
         }
         $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDDEN, $isOverridden);
         $this->_quote->getPayment()->save();
     }
     /** @var $cart \Magento\Payment\Model\Cart */
     $cart = $this->_cartFactory->create(['salesModel' => $this->_quote]);
     $this->_api->setPaypalCart($cart);
     if (!$this->_taxData->getConfig()->priceIncludesTax()) {
         $this->setShippingOptions($cart, $address);
     }
     $this->_config->exportExpressCheckoutStyleSettings($this->_api);
     /* Temporary solution. @TODO: do not pass quote into Nvp model */
     $this->_api->setQuote($this->_quote);
     $this->_api->callSetExpressCheckout();
     $token = $this->_api->getToken();
     $this->_setRedirectUrl($button, $token);
     $payment = $this->_quote->getPayment();
     $payment->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
     // Set flag that we came from Express Checkout button
     if (!empty($button)) {
         $payment->setAdditionalInformation(self::PAYMENT_INFO_BUTTON, 1);
     } elseif ($payment->hasAdditionalInformation(self::PAYMENT_INFO_BUTTON)) {
         $payment->unsAdditionalInformation(self::PAYMENT_INFO_BUTTON);
     }
     $payment->save();
     return $token;
 }
예제 #5
0
 /**
  * Place an order with authorization or capture action
  *
  * @param Payment $payment
  * @param float $amount
  * @return $this
  */
 protected function _placeOrder(Payment $payment, $amount)
 {
     $order = $payment->getOrder();
     // prepare api call
     $token = $payment->getAdditionalInformation(ExpressCheckout::PAYMENT_INFO_TRANSPORT_TOKEN);
     $cart = $this->_cartFactory->create(['salesModel' => $order]);
     $api = $this->getApi()->setToken($token)->setPayerId($payment->getAdditionalInformation(ExpressCheckout::PAYMENT_INFO_TRANSPORT_PAYER_ID))->setAmount($amount)->setPaymentAction($this->_pro->getConfig()->getValue('paymentAction'))->setNotifyUrl($this->_urlBuilder->getUrl('paypal/ipn/'))->setInvNum($order->getIncrementId())->setCurrencyCode($order->getBaseCurrencyCode())->setPaypalCart($cart)->setIsLineItemsEnabled($this->_pro->getConfig()->getValue('lineItemsEnabled'));
     if ($order->getIsVirtual()) {
         $api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
     } else {
         $api->setAddress($order->getShippingAddress());
         $api->setBillingAddress($order->getBillingAddress());
     }
     // call api and get details from it
     $api->callDoExpressCheckoutPayment();
     $this->_importToPayment($api, $payment);
     return $this;
 }