/** * 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; }
/** * 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; }
/** * Call DoAuthorize * * @param int $amount * @param \Magento\Framework\DataObject $payment * @param string $parentTransactionId * @return \Magento\Paypal\Model\Api\AbstractApi */ protected function _callDoAuthorize($amount, $payment, $parentTransactionId) { $apiData = $this->_pro->getApi()->getData(); foreach ($apiData as $k => $v) { if (is_object($v)) { unset($apiData[$k]); } } $this->_checkoutSession->setPaypalTransactionData($apiData); $this->_pro->resetApi(); $api = $this->_setApiProcessableErrors()->setAmount($amount)->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode())->setTransactionId($parentTransactionId)->callDoAuthorization(); $payment->setAdditionalInformation($this->_authorizationCountKey, $payment->getAdditionalInformation($this->_authorizationCountKey) + 1); return $api; }