Example #1
0
 public function testAccumulateByMapFromAndToAreArrays()
 {
     $from['value'] = 'from_value';
     $map[false] = 'value';
     $to['key'] = 'to_value';
     $default['new_key'] = 'value';
     $expected['key'] = 'to_value';
     $expected['value'] = 'from_value';
     $expected['new_key'] = 'value';
     $this->assertEquals($expected, $this->mapper->accumulateByMap($from, $to, $map, $default));
 }
Example #2
0
 /**
  * Import $this public data from a private response array
  *
  * @param array $privateResponseMap
  * @param array $response
  * @return void
  */
 protected function _importFromResponse(array $privateResponseMap, array $response)
 {
     $map = [];
     foreach ($privateResponseMap as $key) {
         if (isset($this->_globalMap[$key])) {
             $map[$key] = $this->_globalMap[$key];
         }
         if (isset($response[$key]) && isset($this->_importFromRequestFilters[$key])) {
             $callback = $this->_importFromRequestFilters[$key];
             $response[$key] = call_user_func([$this, $callback], $response[$key], $key, $map[$key]);
         }
     }
     \Magento\Framework\Object\Mapper::accumulateByMap($response, [$this, 'setDataUsingMethod'], $map);
 }
Example #3
0
 /**
  * Grab data from payment and map it into target
  *
  * @param \Magento\Payment\Model\Info $payment
  * @param array|\Magento\Framework\Object|callback $to
  * @param array|null $map
  * @return array|\Magento\Framework\Object
  */
 public function &exportFromPayment(\Magento\Payment\Model\Info $payment, $to, array $map = null)
 {
     $fullMap = array_merge($this->_paymentMap, $this->_systemMap);
     \Magento\Framework\Object\Mapper::accumulateByMap(array($payment, 'getAdditionalInformation'), $to, $map ? $map : array_flip($fullMap));
     return $to;
 }
Example #4
0
 /**
  * Prepare request to gateway
  *
  * @param \Magento\Framework\Object|\Magento\Payment\Model\Info $payment
  * @return \Magento\Authorizenet\Model\Authorizenet\Request
  * @link http://www.authorize.net/support/AIM_guide.pdf
  */
 protected function _buildRequest(\Magento\Framework\Object $payment)
 {
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     $request = $this->_getRequest()->setXType($payment->getAnetTransType())->setXMethod(self::REQUEST_METHOD_CC);
     if ($order && $order->getIncrementId()) {
         $request->setXInvoiceNum($order->getIncrementId());
     }
     if ($payment->getAmount()) {
         $request->setXAmount($payment->getAmount(), 2);
         $request->setXCurrencyCode($order->getBaseCurrencyCode());
     }
     switch ($payment->getAnetTransType()) {
         case self::REQUEST_TYPE_AUTH_CAPTURE:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
                 $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
             }
             break;
         case self::REQUEST_TYPE_AUTH_ONLY:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
                 $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
             }
             break;
         case self::REQUEST_TYPE_CREDIT:
             /**
              * Send last 4 digits of credit card number to authorize.net
              * otherwise it will give an error
              */
             $request->setXCardNum($payment->getCcLast4());
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_VOID:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             $request->setXAuthCode($payment->getCcAuthCode());
             break;
     }
     if ($this->getIsCentinelValidationEnabled()) {
         $params = $this->getCentinelValidator()->exportCmpiData(array());
         $request = \Magento\Framework\Object\Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXCustId($order->getCustomerId())->setXCustomerIp($order->getRemoteIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->getConfigData('email_customer'))->setXMerchantEmail($this->getConfigData('merchant_email'));
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreet(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry());
         }
         $request->setXPoNum($payment->getPoNumber())->setXTax($order->getBaseTaxAmount())->setXFreight($order->getBaseShippingAmount());
     }
     if ($payment->getCcNumber()) {
         $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid());
     }
     return $request;
 }
Example #5
0
 /**
  * Return request object with information for 'authorization' or 'sale' action
  *
  * @param \Magento\Framework\Object|Payment $payment
  * @param float $amount
  * @return \Magento\Framework\Object
  */
 protected function _buildPlaceRequest(\Magento\Framework\Object $payment, $amount)
 {
     $request = $this->_buildBasicRequest($payment);
     $request->setAmt(round($amount, 2));
     $request->setAcct($payment->getCcNumber());
     $request->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2));
     $request->setCvv2($payment->getCcCid());
     if ($this->getIsCentinelValidationEnabled()) {
         $params = array();
         $params = $this->getCentinelValidator()->exportCmpiData($params);
         $request = \Magento\Framework\Object\Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
     }
     $order = $payment->getOrder();
     if (!empty($order)) {
         $request->setCurrency($order->getBaseCurrencyCode());
         $orderIncrementId = $order->getIncrementId();
         $request->setCurrency($order->getBaseCurrencyCode())->setInvnum($orderIncrementId)->setPonum($order->getId())->setComment1($orderIncrementId);
         $customerId = $order->getCustomerId();
         if ($customerId) {
             $request->setCustref($customerId);
         }
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setFirstname($billing->getFirstname())->setLastname($billing->getLastname())->setStreet(implode(' ', $billing->getStreet()))->setCity($billing->getCity())->setState($billing->getRegionCode())->setZip($billing->getPostcode())->setCountry($billing->getCountry())->setEmail($payment->getOrder()->getCustomerEmail());
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet(implode(' ', $shipping->getStreet()))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegionCode())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountry());
         }
     }
     return $request;
 }
Example #6
0
 /**
  * Submit RP to the gateway
  *
  * @param RecurringPayment $payment
  * @param PaymentInfo $paymentInfo
  * @return void
  */
 public function submit(RecurringPayment $payment, PaymentInfo $paymentInfo)
 {
     $token = $paymentInfo->getAdditionalInformation(PayPalExpress\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN);
     $payment->setToken($token);
     $api = $this->_paymentMethod->getApi();
     \Magento\Framework\Object\Mapper::accumulateByMap($payment, $api, array('token', 'subscriber_name', 'start_datetime', 'internal_reference_id', 'schedule_description', 'suspension_threshold', 'bill_failed_later', 'period_unit', 'period_frequency', 'period_max_cycles', 'billing_amount' => 'amount', 'trial_period_unit', 'trial_period_frequency', 'trial_period_max_cycles', 'trial_billing_amount', 'currency_code', 'shipping_amount', 'tax_amount', 'init_amount', 'init_may_fail'));
     $api->callCreateRecurringPayment();
     $payment->setReferenceId($api->getRecurringPaymentId());
     if ($api->getIsPaymentActive()) {
         $payment->setState(States::ACTIVE);
     } elseif ($api->getIsPaymentPending()) {
         $payment->setState(States::PENDING);
     }
 }
Example #7
0
 /**
  * Prepare request data basing on provided addresses
  *
  * @param array $to
  * @return array
  */
 protected function _importAddresses(array $to)
 {
     $billingAddress = $this->getBillingAddress() ? $this->getBillingAddress() : $this->getAddress();
     $shippingAddress = $this->getAddress();
     $to = \Magento\Framework\Object\Mapper::accumulateByMap($billingAddress, $to, array_merge(array_flip($this->_billingAddressMap), $this->_billingAddressMapRequest));
     $regionCode = $this->_lookupRegionCodeFromAddress($billingAddress);
     if ($regionCode) {
         $to['STATE'] = $regionCode;
     }
     if (!$this->getSuppressShipping()) {
         $to = \Magento\Framework\Object\Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap));
         $regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress);
         if ($regionCode) {
             $to['SHIPTOSTATE'] = $regionCode;
         }
         $this->_importStreetFromAddress($shippingAddress, $to, 'SHIPTOSTREET', 'SHIPTOSTREET2');
         $this->_importStreetFromAddress($billingAddress, $to, 'STREET', 'STREET2');
         $to['SHIPTONAME'] = $shippingAddress->getName();
     }
     return $to;
 }
Example #8
0
 /**
  * Export cmpi lookups and authentication information stored in session into array
  *
  * @param array|object $to
  * @param array|bool $map
  * @return array|object
  */
 public function exportCmpiData($to, $map = false)
 {
     if (!$map) {
         $map = $this->_cmpiMap;
     }
     if ($validationState = $this->_getValidationState()) {
         $to = \Magento\Framework\Object\Mapper::accumulateByMap($validationState, $to, $map);
     }
     return $to;
 }
Example #9
0
 /**
  * Import address object, if set, to the request
  *
  * @param array $request
  * @return void
  */
 protected function _importAddress(&$request)
 {
     $address = $this->getAddress();
     if (!$address) {
         if ($this->getNoShipping()) {
             $request['no_shipping'] = 1;
         }
         return;
     }
     $request = \Magento\Framework\Object\Mapper::accumulateByMap($address, $request, array_flip($this->_addressMap));
     // Address may come without email info (user is not always required to enter it), so add email from order
     if (!$request['email']) {
         $order = $this->getOrder();
         if ($order) {
             $request['email'] = $order->getCustomerEmail();
         }
     }
     $regionCode = $this->_lookupRegionCodeFromAddress($address);
     if ($regionCode) {
         $request['state'] = $regionCode;
     }
     $this->_importStreetFromAddress($address, $request, 'address1', 'address2');
     $request['address_override'] = 1;
 }