/**
  * Submit recurring payments
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 public function submitRecurringPayments($observer)
 {
     $this->_recurringPayments = $this->_quoteImporter->import($observer->getEvent()->getQuote());
     foreach ($this->_recurringPayments as $payment) {
         if (!$payment->isValid()) {
             throw new \Magento\Framework\Model\Exception($payment->getValidationErrors());
         }
         $payment->submit();
     }
 }
示例#2
0
文件: Nvp.php 项目: aiesh/magento2
 /**
  * SetExpressCheckout call
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout
  * TODO: put together style and giropay settings
  */
 public function callSetExpressCheckout()
 {
     $this->_prepareExpressCheckoutCallRequest($this->_setExpressCheckoutRequest);
     $request = $this->_exportToRequest($this->_setExpressCheckoutRequest);
     $this->_exportLineItems($request);
     // import/suppress shipping address, if any
     $options = $this->getShippingOptions();
     if ($this->getAddress()) {
         $request = $this->_importAddresses($request);
         $request['ADDROVERRIDE'] = 1;
     } elseif ($options && count($options) <= 10) {
         // doesn't support more than 10 shipping options
         $request['CALLBACK'] = $this->getShippingOptionsCallbackUrl();
         $request['CALLBACKTIMEOUT'] = 6;
         // max value
         $request['MAXAMT'] = $request['AMT'] + 999.0;
         // it is impossible to calculate max amount
         $this->_exportShippingOptions($request);
     }
     $payments = $this->_quoteImporter->import($this->getQuote());
     if ($payments) {
         $i = 0;
         foreach ($payments as $payment) {
             $payment->setMethodCode(\Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS);
             if (!$payment->isValid()) {
                 throw new \Magento\Framework\Model\Exception($payment->getValidationErrors());
             }
             $request["L_BILLINGTYPE{$i}"] = 'RecurringPayments';
             $request["L_BILLINGAGREEMENTDESCRIPTION{$i}"] = $payment->getScheduleDescription();
             $i++;
         }
     }
     $response = $this->call(self::SET_EXPRESS_CHECKOUT, $request);
     $this->_importFromResponse($this->_setExpressCheckoutResponse, $response);
 }