function it_should_parse_only_two_letters_emp_endpoint()
 {
     \Genesis\Config::setEndpoint(\Genesis\API\Constants\Endpoints::EMERCHANTPAY);
     $this->setLanguage('en_US');
     $this->getApiConfig('url')->shouldContainString('wpf.emerchantpay.net:443/en/wpf');
     $this->setLanguage('zh_ZH');
     $this->getApiConfig('url')->shouldContainString('wpf.emerchantpay.net:443/zh/wpf');
 }
 /**
  * Set the the Credentials and Environment to the Gateway Client
  * @return void
  * @throws \Genesis\Exceptions\InvalidArgument
  */
 public function initGatewayClient()
 {
     \Genesis\Config::setEndpoint(\Genesis\API\Constants\Endpoints::EMERCHANTPAY);
     \Genesis\Config::setUsername($this->getUserName());
     \Genesis\Config::setPassword($this->getPassword());
     $token = $this->getToken();
     if (!empty($token)) {
         \Genesis\Config::setToken($token);
     }
     \Genesis\Config::setEnvironment($this->getIsStagingMode() ? \Genesis\API\Constants\Environments::STAGING : \Genesis\API\Constants\Environments::PRODUCTION);
 }
 function __construct()
 {
     for ($i = 0; $i < mt_rand(32, 48); $i++) {
         $this->sample['api']['unique_id'] .= chr(mt_rand(97, 122));
     }
     $this->sample['api']['signature'] = hash('sha1', $this->sample['api']['unique_id'] . \Genesis\Config::getPassword());
     for ($i = 0; $i < mt_rand(32, 48); $i++) {
         $this->sample['wpf']['wpf_unique_id'] .= chr(mt_rand(97, 122));
     }
     $this->sample['wpf']['signature'] = hash('sha1', $this->sample['wpf']['wpf_unique_id'] . \Genesis\Config::getPassword());
 }
Example #4
0
 /**
  * Initialize the required builder, based on the use's
  * preference (set inside the configuration ini file)
  *
  * @param string $interface
  */
 public function __construct($interface = null)
 {
     $interface = $interface ?: \Genesis\Config::getInterface('parser');
     switch ($interface) {
         default:
         case 'xml':
             $this->context = new Parsers\XML();
             break;
         case 'json':
             break;
     }
 }
Example #5
0
 function send_remote_connection($remote_url)
 {
     $faker = \Faker\Factory::create();
     $faker->addProvider(new \Faker\Provider\UserAgent($faker));
     $options = array('body' => '', 'type' => 'GET', 'url' => $remote_url, 'timeout' => Config::getNetworkTimeout(), 'ca_bundle' => Config::getCertificateBundle(), 'user_login' => Config::getUsername() . ':' . Config::getPassword(), 'user_agent' => $faker->userAgent);
     $this->prepareRequestBody($options);
     $this->shouldNotThrow()->during('execute');
     $this->getResponseBody()->shouldNotBeEmpty();
     // Check only the gate for time as its the only endpoint that provides server-time
     if (strpos($remote_url, 'gate.')) {
         $this->getResponseBody()->shouldNotBeOlder();
     }
     $this->getStatus()->shouldBe(200);
 }
 /**
  * Check if the current system fulfils the project's dependencies
  *
  * @throws \Exception
  */
 public static function verify()
 {
     // PHP interpreter version
     self::checkSystemVersion();
     // BCMath
     self::isFunctionExists('bcmul', self::getErrorMessage('bcmath'));
     self::isFunctionExists('bcdiv', self::getErrorMessage('bcmath'));
     // Filter
     self::isFunctionExists('filter_var', self::getErrorMessage('filter'));
     // Hash
     self::isFunctionExists('hash', self::getErrorMessage('hash'));
     // XMLReader
     self::isClassExists('XMLReader', self::getErrorMessage('xmlreader'));
     // XMLWriter
     if (\Genesis\Config::getInterface('builder') == 'xml') {
         self::isClassExists('XMLWriter', self::getErrorMessage('xmlwriter'));
     }
     // cURL
     if (\Genesis\Config::getInterface('network') == 'curl') {
         self::isFunctionExists('curl_init', self::getErrorMessage('curl'));
     }
 }
Example #7
0
 /**
  * Set the per-request configuration
  *
  * @return void
  */
 protected function initConfiguration()
 {
     $this->config = \Genesis\Utils\Common::createArrayObject(array('protocol' => 'https', 'port' => 443, 'type' => 'POST', 'format' => 'xml'));
     $this->setApiConfig('url', $this->buildRequestURL('gateway', 'reconcile/by_date', \Genesis\Config::getToken()));
 }
 /**
  * Build the complete URL for the request
  *
  * @param $subDomain  String   - gateway/wpf etc.
  * @param $path        String   - path of the current request
  * @param $appendToken Bool     - should we append the token to the end of the url
  *
  * @return string               - complete URL (sub_domain,path,token)
  */
 protected function buildRequestURL($subDomain = 'gateway', $path = '/', $appendToken = true)
 {
     $token = $appendToken ? \Genesis\Config::getToken() : '';
     $baseURL = \Genesis\Config::getEnvironmentURL($this->getApiConfig('protocol'), $subDomain, $this->getApiConfig('port'));
     return sprintf('%s/%s/%s', $baseURL, $path, $token);
 }
 function it_should_build_correct_url_for_emp_endpoint()
 {
     \Genesis\Config::setEndpoint(\Genesis\API\Constants\Endpoints::EMERCHANTPAY);
     $this->getApiConfig('url')->shouldBe('https://staging.gate.emerchantpay.net:443/retrieve_abn_ideal_banks');
 }
 /**
  * Verify the signature on the parsed Notification
  *
  * @return bool
  * @throws \Genesis\Exceptions\InvalidArgument
  */
 public function isAuthentic()
 {
     if (!isset($this->unique_id) || !isset($this->notificationObj->signature)) {
         throw new \Genesis\Exceptions\InvalidArgument('Missing field(s), required for validation!');
     }
     $messageSig = trim($this->notificationObj->signature);
     $customerPwd = trim(\Genesis\Config::getPassword());
     switch (strlen($messageSig)) {
         default:
         case 40:
             $hashType = 'sha1';
             break;
         case 128:
             $hashType = 'sha512';
             break;
     }
     if ($messageSig === hash($hashType, $this->unique_id . $customerPwd)) {
         return true;
     }
     return false;
 }
 function it_should_have_default_environment_url_for_emp_endpoint()
 {
     \Genesis\Config::setEndpoint(\Genesis\API\Constants\Endpoints::EMERCHANTPAY);
     $this->getApiConfig('url')->shouldBe('https://staging.gate.emerchantpay.net:443/blacklists');
 }
Example #12
0
 /**
  * During "Checkout" we don't know a Token,
  * however its required at a latter stage, which
  * means we have to extract it from the payment
  * data. We save the token when we receive a
  * notification from Genesis.
  *
  * @param \Magento\Sales\Model\Order\Payment\Transaction $paymentTransaction
  *
  * @return bool
  */
 public function setTokenByPaymentTransaction($paymentTransaction)
 {
     if (!isset($paymentTransaction) || empty($paymentTransaction)) {
         return false;
     }
     $transactionTerminalToken = $this->getTransactionTerminalToken($paymentTransaction);
     if (!empty($transactionTerminalToken)) {
         \Genesis\Config::setToken($transactionTerminalToken);
         return true;
     }
     return false;
 }
 /**
  * Set Header/Body of the HTTP request
  *
  * @param \Genesis\API\Request $apiContext
  */
 public function setApiCtxData($apiContext)
 {
     $this->context->prepareRequestBody(array('body' => $apiContext->getDocument(), 'url' => $apiContext->getApiConfig('url'), 'type' => $apiContext->getApiConfig('type'), 'port' => $apiContext->getApiConfig('port'), 'protocol' => $apiContext->getApiConfig('protocol'), 'timeout' => \Genesis\Config::getNetworkTimeout(), 'ca_bundle' => \Genesis\Config::getCertificateBundle(), 'user_agent' => sprintf('Genesis PHP Client v%s', \Genesis\Config::getVersion()), 'user_login' => sprintf('%s:%s', \Genesis\Config::getUsername(), \Genesis\Config::getPassword())));
 }
 /**
  * During "Checkout" we don't know have a Token,
  * however its required at a latter stage, which
  * means we have to extract it from the payment
  * data. We save the token when we receive a
  * notification from Genesis, then we only have
  * to find the earliest payment_transaction
  *
  * @param Mage_Sales_Model_Order_Payment $payment
  *
  * @return void
  */
 public function setTokenByPaymentTransaction($payment)
 {
     $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->setOrderFilter($payment->getOrder())->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_ASC);
     /** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
     foreach ($collection as $transaction) {
         $information = $transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS);
         foreach ($information as $field => $value) {
             if ($field == 'terminal_token') {
                 \Genesis\Config::setToken($value);
             }
         }
     }
 }
Example #15
0
 /**
  * Build the complete URL for the request
  *
  * @param $sub      String   - gateway/wpf etc.
  * @param $path     String   - path of the current request
  * @param $token    String   - should we append the token to the end of the url
  *
  * @return string            - complete URL
  */
 protected function buildRequestURL($sub = 'gateway', $path = '', $token = '')
 {
     $protocol = $this->getApiConfig('protocol') ? $this->getApiConfig('protocol') : 'https';
     $sub = \Genesis\Config::getSubDomain($sub);
     $domain = \Genesis\Config::getEndpoint();
     $port = $this->getApiConfig('port') ? $this->getApiConfig('port') : 443;
     $path = $token ? sprintf('%s/%s/', $path, $token) : $path;
     return sprintf('%s://%s%s:%s/%s', $protocol, $sub, $domain, $port, $path);
 }