Ejemplo n.º 1
0
 /**
  * Create a Web-Payment Form Instance
  * @param array $data
  * @return \stdClass
  * @throws \Magento\Framework\Webapi\Exception
  */
 protected function checkout($data)
 {
     $genesis = new \Genesis\Genesis('WPF\\Create');
     $genesis->request()->setTransactionId($data['transaction_id'])->setCurrency($data['order']['currency'])->setAmount($data['order']['amount'])->setUsage($data['order']['usage'])->setDescription($data['order']['description'])->setCustomerPhone(strval($data['order']['billing']->getTelephone()))->setCustomerEmail(strval($data['order']['customer']['email']))->setNotificationUrl($data['urls']['notify'])->setReturnSuccessUrl($data['urls']['return_success'])->setReturnFailureUrl($data['urls']['return_failure'])->setReturnCancelUrl($data['urls']['return_cancel'])->setBillingFirstName(strval($data['order']['billing']->getFirstname()))->setBillingLastName(strval($data['order']['billing']->getLastname()))->setBillingAddress1(strval($data['order']['billing']->getStreetLine(1)))->setBillingAddress2(strval($data['order']['billing']->getStreetLine(2)))->setBillingZipCode(strval($data['order']['billing']->getPostcode()))->setBillingCity(strval($data['order']['billing']->getCity()))->setBillingState(strval($data['order']['billing']->getRegionCode()))->setBillingCountry(strval($data['order']['billing']->getCountryId()))->setLanguage($data['order']['language']);
     if (!empty($data['order']['shipping'])) {
         $genesis->request()->setShippingFirstName(strval($data['order']['shipping']->getFirstname()))->setShippingLastName(strval($data['order']['shipping']->getLastname()))->setShippingAddress1(strval($data['order']['shipping']->getStreetLine(1)))->setShippingAddress2(strval($data['order']['shipping']->getStreetLine(2)))->setShippingZipCode(strval($data['order']['shipping']->getPostcode()))->setShippingCity(strval($data['order']['shipping']->getCity()))->setShippingState(strval($data['order']['shipping']->getRegionCode()))->setShippingCountry(strval($data['order']['shipping']->getCountryId()));
     }
     foreach ($this->getCheckoutTransactionTypes() as $type) {
         if (is_array($type)) {
             $genesis->request()->addTransactionType($type['name'], $type['parameters']);
         } else {
             if (\Genesis\API\Constants\Transaction\Types::isPayByVoucher($type)) {
                 $parameters = ['card_type' => \Genesis\API\Constants\Transaction\Parameters\PayByVouchers\CardTypes::VIRTUAL, 'redeem_type' => \Genesis\API\Constants\Transaction\Parameters\PayByVouchers\RedeemTypes::INSTANT];
                 if ($type == \Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_YEEPAY) {
                     $parameters['product_name'] = $data['order']['description'];
                     $parameters['product_category'] = $data['order']['description'];
                 }
                 $genesis->request()->addTransactionType($type, $parameters);
             } else {
                 $genesis->request()->addTransactionType($type);
             }
         }
     }
     $genesis->execute();
     return $genesis->response()->getResponseObject();
 }
Ejemplo n.º 2
0
 /**
  * Verify that transaction type parameters are populated correctly
  *
  * @param string $transactionType
  * @param array $parameters
  * @throws \Genesis\Exceptions\ErrorParameter
  */
 protected function verifyTransactionType($transactionType, $parameters = array())
 {
     if (!\Genesis\API\Constants\Transaction\Types::isValidTransactionType($transactionType)) {
         throw new \Genesis\Exceptions\ErrorParameter(sprintf('Transaction type (%s) is not valid', $transactionType));
     }
     $transactionCustomRequiredParams = \Genesis\API\Constants\Transaction\Types::getCustomRequiredParameters($transactionType);
     if (\Genesis\Utils\Common::isValidArray($transactionCustomRequiredParams)) {
         foreach ($transactionCustomRequiredParams as $customRequiredParam => $customRequiredParamValues) {
             if (!array_key_exists($customRequiredParam, $parameters)) {
                 foreach ($parameters as $parameter) {
                     if (!\Genesis\Utils\Common::isValidArray($parameter) || !array_key_exists($customRequiredParam, $parameter)) {
                         throw new \Genesis\Exceptions\ErrorParameter(sprintf('Empty (null) required parameter: %s for transaction type %s', $customRequiredParam, $transactionType));
                     }
                 }
             }
             if (!empty($customRequiredParamValues) && \Genesis\Utils\Common::isValidArray($customRequiredParamValues)) {
                 if (!\Genesis\Utils\Common::arrayContainsArrayItems($parameters)) {
                     if (!in_array($parameters[$customRequiredParam], $customRequiredParamValues)) {
                         sprintf('Invalid value (%s) for required parameter: %s (Transaction type: %s)', $parameters[$customRequiredParam], $customRequiredParam, $transactionType);
                     }
                 } else {
                     foreach ($parameters as $parameter) {
                         if (!in_array($parameter[$customRequiredParam], $customRequiredParamValues)) {
                             throw new \Genesis\Exceptions\ErrorParameter(sprintf('Invalid value (%s) for required parameter: %s (Transaction type: %s)', $parameter[$customRequiredParam], $customRequiredParam, $transactionType));
                         }
                     }
                 }
             }
         }
     }
 }