diff --git a/app/code/community/Sign2pay/Payment/Block/Form/Sign2pay.php b/app/code/community/Sign2pay/Payment/Block/Form/Sign2pay.php
index 7bed8d6..1b2cf66 100644
--- a/app/code/community/Sign2pay/Payment/Block/Form/Sign2pay.php
+++ b/app/code/community/Sign2pay/Payment/Block/Form/Sign2pay.php
@@ -6,6 +6,12 @@ protected function _construct()
{
parent::_construct();
$this->setTemplate('sign2pay/form/sign2pay.phtml');
+
+ if (Mage::getStoreConfig('payment/sign2pay/logo_enabled', Mage::app()->getStore())) {
+ $this
+ ->setMethodLabelAfterHtml($this->_getMarkHtml())
+ ->setMethodTitle(' ' . Mage::getStoreConfig('payment/sign2pay/title', Mage::app()->getStore()));
+ }
}
protected function _prepareLayout()
@@ -21,6 +27,12 @@ protected function _prepareLayout()
}
}
+ protected function _getMarkHtml()
+ {
+ $height = Mage::getStoreConfig('payment/sign2pay/logo_width', Mage::app()->getStore());
+ return '';
+ }
+
public function getOrderId()
{
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
diff --git a/app/code/community/Sign2pay/Payment/Block/Redirect.php b/app/code/community/Sign2pay/Payment/Block/Redirect.php
index ee11e16..cedbd53 100644
--- a/app/code/community/Sign2pay/Payment/Block/Redirect.php
+++ b/app/code/community/Sign2pay/Payment/Block/Redirect.php
@@ -15,9 +15,7 @@ protected function _prepareLayout()
parent::_prepareLayout();
$this->setTemplate('sign2pay/redirect.phtml');
- Mage::helper('sign2pay')->attachPaymentScripts(array(
- 'initialize' => true
- ));
+ Mage::helper('sign2pay')->attachPaymentScripts();
return $this;
}
diff --git a/app/code/community/Sign2pay/Payment/Helper/CountryCodes.php b/app/code/community/Sign2pay/Payment/Helper/CountryCodes.php
new file mode 100644
index 0000000..a029a83
--- /dev/null
+++ b/app/code/community/Sign2pay/Payment/Helper/CountryCodes.php
@@ -0,0 +1,269 @@
+ '93',
+ 'AX' => '35818',
+ 'NL' => '31',
+ 'AN' => '599',
+ 'AL' => '355',
+ 'DZ' => '213',
+ 'AS' => '685',
+ 'AD' => '376',
+ 'AO' => '244',
+ 'AI' => '1264',
+ 'AQ' => '672',
+ 'AG' => '1268',
+ 'AE' => '971',
+ 'AR' => '54',
+ 'AM' => '374',
+ 'AW' => '297',
+ 'AU' => '61',
+ 'AZ' => '994',
+ 'BS' => '1242',
+ 'BH' => '973',
+ 'BD' => '880',
+ 'BB' => '1242',
+ 'BE' => '32',
+ 'BZ' => '501',
+ 'BJ' => '229',
+ 'BM' => '1441',
+ 'BT' => '975',
+ 'BO' => '591',
+ 'BA' => '387',
+ 'BW' => '267',
+ 'BV' => '47',
+ 'BR' => '55',
+ 'GB' => '44',
+ 'IO' => '246',
+ 'VG' => '1284',
+ 'BN' => '673',
+ 'BG' => '359',
+ 'BF' => '226',
+ 'BI' => '257',
+ 'KY' => '1345',
+ 'CL' => '56',
+ 'CK' => '682',
+ 'CR' => '506',
+ 'DJ' => '253',
+ 'DM' => '1767',
+ 'DO' => '1809',
+ 'EC' => '593',
+ 'EG' => '20',
+ 'SV' => '503',
+ 'ER' => '291',
+ 'ES' => '34',
+ 'ZA' => '27',
+ 'GS' => '500',
+ 'KR' => '82',
+ 'ET' => '251',
+ 'FK' => '500',
+ 'FJ' => '679',
+ 'PH' => '63',
+ 'FO' => '298',
+ 'GA' => '241',
+ 'GM' => '220',
+ 'GE' => '995',
+ 'GH' => '233',
+ 'GI' => '350',
+ 'GD' => '1473',
+ 'GL' => '299',
+ 'GP' => '590',
+ 'GU' => '1671',
+ 'GT' => '502',
+ 'GG' => '44',
+ 'GN' => '224',
+ 'GW' => '245',
+ 'GY' => '592',
+ 'HT' => '509',
+ 'HM' => '61',
+ 'HN' => '504',
+ 'HK' => '852',
+ 'SJ' => '47',
+ 'ID' => '62',
+ 'IN' => '91',
+ 'IQ' => '964',
+ 'IR' => '98',
+ 'IE' => '353',
+ 'IS' => '354',
+ 'IL' => '972',
+ 'IT' => '39',
+ 'TL' => '670',
+ 'AT' => '43',
+ 'JM' => '1876',
+ 'JP' => '81',
+ 'YE' => '967',
+ 'JE' => '44',
+ 'JO' => '962',
+ 'CX' => '61',
+ 'KH' => '855',
+ 'CM' => '237',
+ 'CA' => '1',
+ 'CV' => '238',
+ 'KZ' => '7',
+ 'KE' => '254',
+ 'CF' => '236',
+ 'CN' => '86',
+ 'KG' => '996',
+ 'KI' => '686',
+ 'CO' => '57',
+ 'KM' => '269',
+ 'CG' => '242',
+ 'CD' => '243',
+ 'CC' => '61',
+ 'GR' => '30',
+ 'HR' => '385',
+ 'CU' => '53',
+ 'KW' => '965',
+ 'CY' => '357',
+ 'LA' => '856',
+ 'LV' => '371',
+ 'LS' => '266',
+ 'LB' => '961',
+ 'LR' => '231',
+ 'LY' => '218',
+ 'LI' => '423',
+ 'LT' => '370',
+ 'LU' => '352',
+ 'EH' => '21228',
+ 'MO' => '853',
+ 'MG' => '261',
+ 'MK' => '389',
+ 'MW' => '265',
+ 'MV' => '960',
+ 'MY' => '60',
+ 'ML' => '223',
+ 'MT' => '356',
+ 'IM' => '44',
+ 'MA' => '212',
+ 'MH' => '692',
+ 'MQ' => '596',
+ 'MR' => '222',
+ 'MU' => '230',
+ 'YT' => '262',
+ 'MX' => '52',
+ 'FM' => '691',
+ 'MD' => '373',
+ 'MC' => '377',
+ 'MN' => '976',
+ 'ME' => '382',
+ 'MS' => '1664',
+ 'MZ' => '258',
+ 'MM' => '95',
+ 'NA' => '264',
+ 'NR' => '674',
+ 'NP' => '977',
+ 'NI' => '505',
+ 'NE' => '227',
+ 'NG' => '234',
+ 'NU' => '683',
+ 'NF' => '672',
+ 'NO' => '47',
+ 'CI' => '255',
+ 'OM' => '968',
+ 'PK' => '92',
+ 'PW' => '680',
+ 'PS' => '970',
+ 'PA' => '507',
+ 'PG' => '675',
+ 'PY' => '595',
+ 'PE' => '51',
+ 'PN' => '870',
+ 'KP' => '850',
+ 'MP' => '1670',
+ 'PT' => '351',
+ 'PR' => '1',
+ 'PL' => '48',
+ 'GQ' => '240',
+ 'QA' => '974',
+ 'FR' => '33',
+ 'GF' => '594',
+ 'PF' => '689',
+ 'TF' => '33',
+ 'RO' => '40',
+ 'RW' => '250',
+ 'SE' => '46',
+ 'RE' => '262',
+ 'SH' => '290',
+ 'KN' => '1869',
+ 'LC' => '1758',
+ 'VC' => '1784',
+ 'BL' => '590',
+ 'MF' => '1599',
+ 'PM' => '508',
+ 'DE' => '49',
+ 'SB' => '677',
+ 'ZM' => '260',
+ 'WS' => '685',
+ 'SM' => '378',
+ 'SA' => '966',
+ 'SN' => '221',
+ 'RS' => '381',
+ 'SC' => '248',
+ 'SL' => '232',
+ 'SG' => '65',
+ 'SK' => '421',
+ 'SI' => '386',
+ 'SO' => '252',
+ 'LK' => '94',
+ 'SD' => '249',
+ 'FI' => '358',
+ 'SR' => '594',
+ 'CH' => '41',
+ 'SZ' => '268',
+ 'SY' => '963',
+ 'ST' => '239',
+ 'TJ' => '992',
+ 'TW' => '886',
+ 'TZ' => '255',
+ 'DK' => '45',
+ 'TH' => '66',
+ 'TG' => '228',
+ 'TK' => '690',
+ 'TO' => '676',
+ 'TT' => '1868',
+ 'TN' => '216',
+ 'TR' => '90',
+ 'TM' => '993',
+ 'TC' => '1649',
+ 'TV' => '688',
+ 'TD' => '235',
+ 'CZ' => '420',
+ 'UG' => '256',
+ 'UA' => '380',
+ 'HU' => '36',
+ 'UY' => '598',
+ 'NC' => '687',
+ 'NZ' => '64',
+ 'UZ' => '998',
+ 'BY' => '375',
+ 'VU' => '678',
+ 'VA' => '39',
+ 'VE' => '58',
+ 'RU' => '7',
+ 'VN' => '84',
+ 'EE' => '372',
+ 'WF' => '681',
+ 'US' => '1',
+ 'VI' => '1340',
+ 'UM' => '1',
+ 'ZW' => '263'
+ );
+
+ $country = strtoupper($country);
+ if (array_key_exists($country, $country_codes)) {
+ return $country_codes[$country];
+ }
+ return null;
+ }
+}
diff --git a/app/code/community/Sign2pay/Payment/Helper/Data.php b/app/code/community/Sign2pay/Payment/Helper/Data.php
index 8ceb67c..df782f6 100644
--- a/app/code/community/Sign2pay/Payment/Helper/Data.php
+++ b/app/code/community/Sign2pay/Payment/Helper/Data.php
@@ -2,36 +2,7 @@
class Sign2pay_Payment_Helper_Data extends Mage_Core_Helper_Abstract
{
-
- /**
- * Retrive Sign2Pay merchant id.
- *
- * @return string
- */
- public function getSign2payMerchantId()
- {
- return Mage::getStoreConfig('payment/sign2pay/merchant_id',Mage::app()->getStore());
- }
-
- /**
- * Retrive Sign2Pay token.
- *
- * @return string
- */
- public function getSign2payToken()
- {
- return Mage::getStoreConfig('payment/sign2pay/application_token',Mage::app()->getStore());
- }
-
- /**
- * Retrive Sign2Pay api key.
- *
- * @return string
- */
- public function getSign2payApiKey()
- {
- return Mage::getStoreConfig('payment/sign2pay/api_token',Mage::app()->getStore());
- }
+ const LOGO_URL = 'https://app.sign2pay.com/api/v2/banks/logo.gif';
/**
* Retrive Sign2Pay Client ID.
@@ -53,19 +24,6 @@ public function getSign2payClientSecret()
return Mage::getStoreConfig('payment/sign2pay/client_secret',Mage::app()->getStore());
}
- /**
- * Retrive sign2pay options.
- *
- * @return array
- */
- public function getSign2PayOptions()
- {
- return array(
- 'merchantId' => $this->getSign2payMerchantId(),
- 'token' => $this->getSign2payToken(),
- );
- }
-
/**
* Retrive sign2pay options.
*
@@ -97,15 +55,10 @@ public function getRedirectUri()
*/
public function attachPaymentScripts(array $additional = array())
{
- /**
- * @todo Properly remove/update this functionality
- */
- return;
-
Mage::app()->getLayout()->getBlock('head')->addJs('sign2pay/jquery.min.js');
Mage::app()->getLayout()->getBlock('head')->addJs('sign2pay/payment.js');
- $options = $additional + $this->getSign2PayOptions();
+ $options = $additional;
$options['baseUrl'] = Mage::getBaseUrl();
$script = 'window.s2pOptions = ' . json_encode($options) . ';';
@@ -180,27 +133,39 @@ public function getQuote()
}
/**
- * Prepare and return initial Sign2Pay request
- * @todo device unical id
+ * Get payment amount
*
- * @return string
+ * @return int
*/
- public function getSign2PayInitialRequest()
+ public function getPaymentAmount()
+ {
+ $quote = $this->getQuote();
+ return $quote->getGrandTotal() * 100;
+ }
+
+ /**
+ * Get all payment options applicable to sign2pay request
+ *
+ * @return array
+ */
+ public function getPaymentOptions()
{
$quote = $this->getQuote();
$billaddress = $quote->getBillingAddress();
+ $telephone = trim($billaddress->getTelephone());
+ $telephone = preg_replace('/[^0-9+]/', '', $telephone);
+ $telephone = preg_replace('/^0+/', '+', $telephone);
+
+ if (substr($telephone, 0, 1) !== '+') {
+ $country_code = Mage::helper('sign2pay/countryCodes')->getCountryCallingCode($billaddress->getCountry());
+ $telephone = '+' . $country_code . $telephone;
+ }
+
$options = array();
- $options['client_id'] = $this->getSign2payClientId();
- $options['redirect_uri'] = $this->getRedirectUri();
- $options['amount'] = $quote->getGrandTotal() * 100;
- $options['response_type'] = 'code';
- $options['device_uid'] = 'test';
+ $options['amount'] = $this->getPaymentAmount();
$options['locale'] = preg_replace('/_.*$/', '', Mage::app()->getLocale()->getLocaleCode());
- $options['state'] = $this->userStateHash();
- $options['scope'] = 'payment';
- $options['ref_id'] = $this->sign2PayCheckoutHash($quote->getReservedOrderId());
$options['user_params[identifier]'] = $billaddress->getEmail();
$options['user_params[first_name]'] = $billaddress->getFirstname();
@@ -209,6 +174,40 @@ public function getSign2PayInitialRequest()
$options['user_params[city]'] = $billaddress->getCity();
$options['user_params[country]'] = $billaddress->getCountry();
$options['user_params[postal_code]'] = $billaddress->getPostcode();
+ $options['user_params[mobile]'] = $telephone;
+
+ return $options;
+ }
+
+ /**
+ * Get payment logo url
+ *
+ * @return string
+ */
+ public function getPaymentLogoUrl()
+ {
+ $options = $this->getPaymentOptions();
+ return static::LOGO_URL . (!empty($options['user_params[identifier]']) ? ('?email=' . md5($options['user_params[identifier]'])) : '');
+ }
+
+ /**
+ * Prepare and return initial Sign2Pay request
+ * @todo device unical id
+ *
+ * @return string
+ */
+ public function getSign2PayInitialRequest()
+ {
+ $options = $this->getPaymentOptions();
+ $quote = $this->getQuote();
+
+ $options['client_id'] = $this->getSign2payClientId();
+ $options['redirect_uri'] = $this->getRedirectUri();
+ $options['ref_id'] = $this->sign2PayCheckoutHash($quote->getReservedOrderId());
+ $options['response_type'] = 'code';
+ $options['device_uid'] = 'test';
+ $options['state'] = $this->userStateHash();
+ $options['scope'] = 'payment';
return 'https://app.sign2pay.com/oauth/authorize?' . http_build_query($options);
}
diff --git a/app/code/community/Sign2pay/Payment/Model/Observer.php b/app/code/community/Sign2pay/Payment/Model/Observer.php
index 528ee36..4b6be67 100644
--- a/app/code/community/Sign2pay/Payment/Model/Observer.php
+++ b/app/code/community/Sign2pay/Payment/Model/Observer.php
@@ -25,15 +25,15 @@ public function afterBlockHtml($observer)
| Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL
))
{
- $this->_addInitializeRiskAssessment($transport);
+ $this->_addUpdate($transport);
}
} catch (Exception $e) {
// Add anyway
- $this->_addInitializeRiskAssessment($transport);
+ $this->_addUpdate($transport);
}
} else {
// Add anyway
- $this->_addInitializeRiskAssessment($transport);
+ $this->_addUpdate($transport);
}
}
}
@@ -41,9 +41,9 @@ public function afterBlockHtml($observer)
/**
* Add riska assessment trigger to transport
*/
- protected function _addInitializeRiskAssessment($transport)
+ protected function _addUpdate($transport)
{
- $html = '';
+ $html = '';
$transport->setHtml($transport->getHtml() . $html);
}
}
diff --git a/app/code/community/Sign2pay/Payment/Model/Processor.php b/app/code/community/Sign2pay/Payment/Model/Processor.php
index 9dada9c..d8e540c 100644
--- a/app/code/community/Sign2pay/Payment/Model/Processor.php
+++ b/app/code/community/Sign2pay/Payment/Model/Processor.php
@@ -28,13 +28,68 @@ public function getRequestData($key = null)
return isset($this->_request[$key]) ? $this->_request[$key] : null;
}
+ /**
+ * General payment method responsible for the flow of the operations
+ *
+ * @param array returned by sign2pay api after the initial request
+ *
+ */
+ public function performPayment(array $initial_response)
+ {
+ try{
+ $this->validateInitialResponse($initial_response);
+ $token_response = json_decode($this->sendTokenExchangeRequest($initial_response), true);
+ if (empty($token_response['access_token']['token'])) {
+ if (!empty($token_response['error_description'])) {
+ throw new Exception($token_response['error_description']);
+ }
+ throw new Exception('Token is missing');
+ }
+
+ $payment = json_decode($this->sendPaymentRequest($token_response), true);
+ if (empty($payment['purchase_id'])) {
+ if (!empty($payment['error_description'])) {
+ throw new Exception($payment['error_description']);
+ }
+ throw new Exception('Purchase ID is missing');
+ }
+
+ return $this->processPaymentCaptureResponse($payment);
+ }
+ catch (Exception $e) {
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
+ return Mage::app()->getResponse()->setRedirect('cancel', array('_secure'=>true));
+ }
+ }
+
+
+ /**
+ * Validate the initial response
+ * add error to session and throw exception if something's not right
+ *
+ * @param array returned by sign2pay api after the initial request
+ *
+ */
+ public function validateInitialResponse(array $initial_response)
+ {
+ if ($initial_response['state'] !== Mage::getSingleton('checkout/session')->getSign2PayUserHash()
+ || array_key_exists('error', $initial_response)) {
+
+ if (!empty($initial_response['error_description'])) {
+ throw new Exception($initial_response['error_description']);
+ }
+ throw new Exception('Could not validate the response');
+ }
+ }
+
/**
* Exchange hashed credentials for token (second step of Authrature)
*
*
* @return string (encoded json)
*/
- public function processTokenExchangeRequest(array $data){
+ public function sendTokenExchangeRequest(array $data)
+ {
//start variables preparation
$client_id = Mage::helper('sign2pay')->getSign2payClientId();
$client_secret = Mage::helper('sign2pay')->getSign2payClientSecret();
@@ -64,7 +119,6 @@ public function processTokenExchangeRequest(array $data){
} catch (Zend_Http_Client_Exception $e) {
Mage::logException($e);
}
-
}
/**
@@ -73,7 +127,7 @@ public function processTokenExchangeRequest(array $data){
*
* @return string (encoded json)
*/
- public function processPaymentRequest(array $data){
+ public function sendPaymentRequest(array $data){
//start variables preparation
$client_id = Mage::helper('sign2pay')->getSign2payClientId();
$client_secret = Mage::helper('sign2pay')->getSign2payClientSecret();
@@ -84,7 +138,7 @@ public function processPaymentRequest(array $data){
$request_body = array(
'client_id' => $client_id,
- 'amount' => $quote->getGrandTotal() * 100,
+ 'amount' => Mage::helper('sign2pay')->getPaymentAmount(),
'ref_id' => $ref_id,
'token' => $data['access_token']['token']
);
@@ -96,17 +150,16 @@ public function processPaymentRequest(array $data){
$client->setAuth($client_id,$client_secret);
$client->setParameterPost($request_body);
- try{
+ try {
$response = $client->request();
return $response->getBody();
} catch (Zend_Http_Client_Exception $e) {
Mage::logException($e);
}
-
}
- /*
+ /**
* Get gateway data, validate and run corresponding handler
*
* @param array $request
@@ -119,43 +172,26 @@ public function processPaymentCaptureResponse(array $request)
$this->_request = $request;
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
- $purchase_id = $this->getRequestData('purchase_id');
- Mage::getSingleton('checkout/session')->setPurchaseId($purchase_id);
+ $purchaseId = $this->getRequestData('purchase_id');
+ Mage::getSingleton('checkout/session')->setPurchaseId($purchaseId);
// Load appropriate order
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
if (!$this->_order->getId()) {
throw new Exception('Requested order with id ' . $orderId . ' does not exists.');
}
- $result = array();
- if ($this->_verifyResponse($purchase_id)) {
+ if ($this->_verifyResponse($purchaseId)) {
// Payment was successful, so update the order's state
// and send order email and move to the success page
- $result['status'] = 'success';
- $result['redirect_to'] = Mage::getBaseUrl() . 'sign2pay/payment/success';
- $result['params'] = array(
- 'purchase_id' => $purchaseId
- );
- Mage::getSingleton('checkout/session')->setPurchaseId($purchase_id);
+ Mage::getSingleton('checkout/session')->setPurchaseId($purchaseId);
// Register the payment capture
$this->_registerPaymentCapture();
} else {
// Register the payment failure
$this->_registerPaymentFailure();
+ throw new Exception('Sorry, but we could not process your payment at this time.');
}
-
- if (!$result) {
- // There is a problem in the response we got
- $result['status'] = 'failure';
- $result['redirect_to'] = Mage::getBaseUrl() . 'sign2pay/payment/failure';
- $result['params'] = array(
- 'ref_id' => $orderId,
- 'message' => Mage::helper('sign2pay')->__('Sorry, but we could not process your payment at this time.'),
- );
- }
-
- return $result;
}
/**
diff --git a/app/code/community/Sign2pay/Payment/controllers/PaymentController.php b/app/code/community/Sign2pay/Payment/controllers/PaymentController.php
index 84310e4..ecbb58c 100644
--- a/app/code/community/Sign2pay/Payment/controllers/PaymentController.php
+++ b/app/code/community/Sign2pay/Payment/controllers/PaymentController.php
@@ -40,48 +40,19 @@ public function redirectAction()
*/
public function responseAction()
{
- if (!$this->getRequest()->isGet()) {
- return $this->_redirect('sign2pay/payment/cancel', array('_secure'=>true));
- }
try {
- $data = $this->getRequest()->getParams();
- if (!is_array($data) || $data['state'] !== Mage::getSingleton('checkout/session')->getSign2PayUserHash()
- || array_key_exists('error', $data)){
-
- if(is_array($data)){
- Mage::getSingleton('checkout/session')->addError($data['error_description']);
- }
- Mage::log($data);
- return $this->_redirect('sign2pay/payment/cancel', array('_secure'=>true));
- }
-
- $result = json_decode(Mage::getModel('sign2pay/processor')->processTokenExchangeRequest($data), true);
- if (!is_array($result) || array_key_exists('error', $result)){
-
- if(is_array($result)){
- Mage::getSingleton('checkout/session')->addError($data['error_description']);
- }
- Mage::log($result);
- return $this->_redirect('sign2pay/payment/cancel', array('_secure'=>true));
- }
-
- $payment = json_decode(Mage::getModel('sign2pay/processor')->processPaymentRequest($result), true);
- if (!is_array($payment) || array_key_exists('error', $payment)){
- if(is_array($payment)){
- Mage::getSingleton('checkout/session')->addError($data['error_description']);
- }
- Mage::log($payment);
- return $this->_redirect('sign2pay/payment/cancel', array('_secure'=>true));
+ if (!$this->getRequest()->isGet()) {
+ throw new Exception('Wrong request method');
}
+ $data = $this->getRequest()->getParams();
+ $payment = Mage::getModel('sign2pay/processor')->performPayment($data);
- Mage::getModel('sign2pay/processor')->processPaymentCaptureResponse($payment);
return $this->_redirect('sign2pay/payment/success', array('_secure'=>true));
} catch (Exception $e) {
Mage::logException($e);
$this->getResponse()->setHttpResponseCode(500);
}
-
}
/**
@@ -119,10 +90,21 @@ public function cancelAction()
Mage::getModel('sign2pay/processor')->cancel($order);
}
Mage::helper('sign2pay/checkout')->restoreQuote();
- Mage::getSingleton('checkout/session')->addError("You've cancelled the Sign2Pay screen.");
+ Mage::getSingleton('checkout/session')->addError("The payment has been cancelled.");
}
$this->_redirect('checkout/cart');
}
+ /**
+ * Fetch payment logo url
+ */
+ public function fetchPaymentLogoAction()
+ {
+ $options['logo'] = Mage::helper('sign2pay')->getPaymentLogoUrl();
+
+ $jsonData = json_encode($options);
+ $this->getResponse()->setHeader('Content-type', 'application/json');
+ $this->getResponse()->setBody($jsonData);
+ }
}
diff --git a/app/code/community/Sign2pay/Payment/etc/config.xml b/app/code/community/Sign2pay/Payment/etc/config.xml
index a2ccc54..b90ca3d 100644
--- a/app/code/community/Sign2pay/Payment/etc/config.xml
+++ b/app/code/community/Sign2pay/Payment/etc/config.xml
@@ -2,7 +2,7 @@
- 0.7.3
+ 0.7.4
@@ -64,6 +64,8 @@
sale
1
mage_world
+ 1
+ 20
diff --git a/app/code/community/Sign2pay/Payment/etc/system.xml b/app/code/community/Sign2pay/Payment/etc/system.xml
index 6ee8fa0..74490fb 100644
--- a/app/code/community/Sign2pay/Payment/etc/system.xml
+++ b/app/code/community/Sign2pay/Payment/etc/system.xml
@@ -197,6 +197,26 @@
validate-number
+
+
+ Enable logo on the checkout page
+ select
+ adminhtml/system_config_source_yesno
+ 3
+ 1
+ 1
+ 1
+
+
+
+
+ text
+ 4
+ 1
+ 1
+ 1
+
+
//
diff --git a/js/sign2pay/payment.js b/js/sign2pay/payment.js
index 10ed2c6..35a6e71 100644
--- a/js/sign2pay/payment.js
+++ b/js/sign2pay/payment.js
@@ -6,7 +6,7 @@
throw new Error('Sign2Pay: ' + msg);
}
- var Sign2Pay = (function (settings) {
+ var Sign2Pay = (function () {
/**
* Sign2Pay constructor
@@ -15,63 +15,25 @@
*/
function Sign2Pay(settings) {
- this.merchantId = settings.merchantId || throwError('No merchant id');
- this.token = settings.token || throwError('No token');
this.baseUrl = settings.baseUrl || throwError('No base url');
// Remove protocol from base url
this.baseUrl = this.baseUrl.replace(/^http:/, '');
-
- if (settings.initialize) this.initializePayment();
- }
-
- /**
- * @var Default options
- */
-
- Sign2Pay.prototype.defaultOptions = {
- domain: "sign2pay.com",
- el: "#sign2pay"
- }
-
- /**
- * Initialize Sign2Pay transport with given options
- *
- * @param object options
- */
- Sign2Pay.prototype.initTransport = function(options) {
- if (!this.scriptAttached) {
- this.scriptAttached = true;
- $('head').append('');
- }
-
- var interval;
- interval = setInterval(function() {
- if (typeof window.s2p !== 'object' || typeof window.s2p.options !== 'object') return;
- clearInterval(interval);
- window.sign2PayOptions = options;
- window.s2p.options.initTransport();
- });
}
/**
- * Fetches all payment related options
+ * Fetches payment logo
*
* @param function callback
*/
- Sign2Pay.prototype.fetchPaymentOptions = function(callback) {
+ Sign2Pay.prototype.fetchPaymentLogo = function(callback) {
var self = this;
- $.ajax(this.baseUrl + 'sign2pay/payment/fetchPaymentOptions', {
+ $.ajax(this.baseUrl + 'sign2pay/payment/fetchPaymentLogo', {
type: 'POST',
dataType: 'json',
success: function(options) {
- var options = $.extend(self.defaultOptions, options, {
- merchant_id: self.merchantId,
- token: self.token
- });
-
callback(options);
},
error: function(err) {
@@ -82,117 +44,46 @@
}
/**
- * Perform riskAssessment
+ * Perform logo update
*/
- Sign2Pay.prototype.riskAssessment = function() {
+ Sign2Pay.prototype.logoUpdate = function() {
var self = this;
- // Disable payment method
- $('input[name="payment[method]"][value="sign2pay"]').attr('disabled', 'disabled');
+ var $mark = $('#sign2pay-mark');
- var callback = function(options) {
- var errors = [];
+ if (!$mark.size()) return;
- $.each(options, function(key, value) {
- if (!value) {
- errors.push(key);
- }
- });
-
- if (errors.length) {
- console.log('[RA] Missing values for: ' + errors.join(', '));
- return;
- }
-
- options['success'] = function() {
- // Enable the Sign2Pay payment method
- $('input[name="payment[method]"][value="sign2pay"]').removeAttr('disabled');
- };
-
- options['checkout_type'] = 'multi';
-
- self.initTransport(options);
+ var callback = function(options) {
+ $mark.attr('src', options.logo);
}
- this.fetchPaymentOptions(callback);
+ this.fetchPaymentLogo(callback);
};
/**
- * Initialize payment
+ * Perform updates
*/
- Sign2Pay.prototype.initializePayment = function() {
- var self = this;
-
- var unloadCallback = function() {
- return 'Leaving this screen might prevent you from completing this purchase.';
- };
-
- var closeCallback = function() {};
-
- var cancelCallback = function() {
- $(window).unbind('beforeunload', unloadCallback);
- window.location = self.baseUrl + "sign2pay/payment/cancel";
- };
-
- var callback = function(options) {
- options['launch'] = "on_load";
- options['map'] = {};
-
- options['success'] = function() {
- var el = $(this.el).get(0);
- $('.s2p-button-text', el).remove();
- $('.s2p-button-banks', el)
- .append('Pay with Sign2Pay')
- .append('Cancel')
- .children('.btn-cancel')
- .on('click', function() {
- cancelCallback();
- return false;
- });
- $('.loading, .s2p-text', el).remove();
- };
-
- options['error'] = function() {
- alert('There was a problem during Sign2Pay initialization. Your ref_id is ' + options['ref_id'] + '.');
-
- closeCallback = cancelCallback;
-
- var el = $(this.el).get(0);
- $(".loading", el).hide();
- };
-
- options['close'] = function(a) {
- closeCallback();
- };
-
- self.initTransport(options);
- };
-
- $(window).on('beforeunload', unloadCallback);
- this.fetchPaymentOptions(callback);
- }
+ Sign2Pay.prototype.update = function() {
+ this.logoUpdate();
+ };
return Sign2Pay;
})();
$(window).load(function() {
- if (!s2pOptions || !s2pOptions['merchantId'] || !s2pOptions['token']) {
- throwError('The Sign2Pay Module is enabled, but you are missing required settings.');
- } else {
- window.sign2payPayment = new Sign2Pay(s2pOptions);
- }
+ window.sign2payPayment = new Sign2Pay(s2pOptions);
});
- window.initializeRiskAssessment = function() {
+ window.updateSign2pay = function() {
var interval;
interval = setInterval(function() {
if (typeof window.sign2payPayment !== 'object') return;
clearInterval(interval);
- // Perform risk assessment
- window.sign2payPayment.riskAssessment();
+ // Perform update
+ window.sign2payPayment.update();
});
};
diff --git a/package.xml b/package.xml
index e5cb57b..5bbff4b 100644
--- a/package.xml
+++ b/package.xml
@@ -1,7 +1,7 @@
Sign2Pay_Mobile_Payments
- 0.7.3
+ 0.7.4
beta
Sign2Pay Commercial License
community
@@ -13,11 +13,13 @@ Analysing hundreds of data points in a single signature, Sign2Pay provides the s
Compatible with: 1.7, 1.8, 1.9
Changes:
-- Fix payment amount in payment request
+- Add dynamic bank logo to payment method label
+- Add mobile phone number to authorize request
+
Sign2PaySign2Payteam@sign2pay.com
- 2015-11-19
-
-
+ 2015-11-24
+
+
5.3.06.0.0