Skip to content

Commit c0ef8fc

Browse files
committed
WPF and Mobile with SDK + removed JSONP calls and implemented with normal Ajax Calls using CORS
1 parent ee4869c commit c0ef8fc

File tree

463 files changed

+31688
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

463 files changed

+31688
-174
lines changed

app/code/community/GlobalExperts/Hypercharge/Model/Cc.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
2525
*/
2626

27-
require_once 'Hypercharge/interfaces.php';
28-
require_once 'Hypercharge/errors.php';
29-
require_once 'Hypercharge/logger.php';
30-
3127
class GlobalExperts_Hypercharge_Model_Cc extends GlobalExperts_Hypercharge_Model_Mobile {
3228

3329
// unique internal payment method identifier

app/code/community/GlobalExperts/Hypercharge/Model/Checkout.php

Lines changed: 102 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,18 @@ public function getAllConfigChannels() {
371371
public function getRedirectUrl() {
372372
$order = $this->getQuote();
373373
$paymentMethod = get_class($order->getPayment()->getMethodInstance());
374-
if ($paymentMethod)
375-
$modelPayment = Mage::getModel($paymentMethod);
376-
else
377-
$modelPayment = $this;
378374

379-
$gate = Mage::helper('bithypercharge/gateway');
375+
$modelPayment = ($paymentMethod) ? Mage::getModel($paymentMethod) : $this;
380376
$hypercharge_channels = $this->getConfigChannels();
377+
378+
// set API call mode
381379
$mode = !$modelPayment->getConfigData('mode');
382-
$transactionTypes = explode(',', $modelPayment->getConfigData('transaction_types'));
380+
if ($mode) {
381+
$mode = Hypercharge\Config::ENV_LIVE;
382+
} else {
383+
$mode = Hypercharge\Config::ENV_SANDBOX;
384+
}
385+
383386
$ttl = $modelPayment->getConfigData('ttl');
384387

385388
if (!$hypercharge_channels) {
@@ -391,29 +394,39 @@ public function getRedirectUrl() {
391394
Mage::throwException('Could not retrieve order information');
392395
return;
393396
}
397+
394398
$currency = $order->getBaseCurrencyCode();
395399
if (!array_key_exists($currency, $hypercharge_channels)) {
396400
Mage::throwException(
397-
'The merchant doesn\'t accept payments for this currency');
401+
'The merchant doesn\'t accept payments for this currency');
398402
return;
399403
}
400-
$gate->setChannel($hypercharge_channels[$currency]['channel']);
401-
$gate->setUsername($hypercharge_channels[$currency]['login']);
402-
$gate->setPassword($hypercharge_channels[$currency]['pass']);
403404

404-
$gate->setMode('live');
405-
if (!$mode)
406-
$gate->setMode('test');
407405

408-
// is editable by user
409-
$editableByUser = (int) $modelPayment->getConfigData('check_address');
406+
Hypercharge\Config::set(
407+
$hypercharge_channels[$currency]['login']
408+
,$hypercharge_channels[$currency]['pass']
409+
,$mode
410+
);
410411

412+
413+
$currency = $order->getBaseCurrencyCode();
414+
if (!array_key_exists($currency, $hypercharge_channels)) {
415+
Mage::throwException(
416+
'The merchant doesn\'t accept payments for this currency');
417+
return;
418+
}
419+
420+
// is editable by user
421+
$editableByUser = (bool) $modelPayment->getConfigData('check_address');
422+
$amount = sprintf("%.02f", $order->getBaseGrandTotal()) * 100;
411423
$billing = $order->getBillingAddress();
424+
412425
$paymentData = array(
413426
'transaction_id' => $order->getRealOrderId(),
414427
'usage' => 'Hypercharge Web Payment Form transaction',
415428
'description' => 'Order number ' . $order->getRealOrderId(),
416-
'amount' => sprintf("%.02f", $order->getBaseGrandTotal()) * 100,
429+
'amount' => (int) $amount,
417430
'currency' => $currency,
418431
'editable_by_user' => $editableByUser,
419432
'customer_email' => $order->getCustomerEmail(),
@@ -429,7 +442,6 @@ public function getRedirectUrl() {
429442
'city' => utf8_decode($billing->getCity()),
430443
'country' => utf8_decode($billing->getCountryId()),
431444
'zip_code' => utf8_decode($billing->getData('postcode')),
432-
'state' => utf8_decode($billing->getData('region'))
433445
),
434446
'shipping_address' => array(
435447
'first_name' => utf8_decode($billing->getFirstname()),
@@ -438,7 +450,6 @@ public function getRedirectUrl() {
438450
'city' => utf8_decode($billing->getCity()),
439451
'country' => utf8_decode($billing->getCountryId()),
440452
'zip_code' => utf8_decode($billing->getData('postcode')),
441-
'state' => utf8_decode($billing->getData('region'))
442453
),
443454
);
444455

@@ -455,48 +466,78 @@ public function getRedirectUrl() {
455466
$paymentData['ttl'] = $ttl;
456467

457468
// Log some information
458-
Mage::helper('bithypercharge')->logger("WPF initiated. Gateway config:\n"
459-
. print_r($gate->getGateway(), true)
460-
. "Mode:" . print_r($gate->getMode(), true)
461-
. "\nRequest string:\n" . '<?xml version="1.0" encoding="utf-8"?>'
462-
. $gate->paramsXML($paymentData, 'wpf_payment'));
463-
464-
if (!$response = $gate->wpf_create($paymentData)) {
465-
$order->addStatusToHistory($order->getStatus(), $gate->__('Could not initiate WPF'));
466-
$order->save();
467-
Mage::getSingleton('core/session')
468-
->addError($gate->__('Could not initiate WPF'));
469-
return;
470-
}
469+
Mage::helper('bithypercharge')->logger("WPF initiated:\n"
470+
. "Mode:" . print_r($mode, true)
471+
. "\nRequest string:\n"
472+
. var_export($paymentData, true));
473+
471474

472-
// Log the response
473-
Mage::helper('bithypercharge')->logger("WPF response received:\n" . print_r($response, true));
474475

475476
// Instantiate payment method to log the response error
476477
$paymentInst = $order->getPayment()->getMethodInstance();
477-
if ($response['status'] == 'error') {
478-
$order->addStatusToHistory($order->getStatus(), $response['message']);
478+
479+
try {
480+
$payment = Hypercharge\Payment::wpf($paymentData);
481+
482+
if ($payment->status == 'error') {
483+
$order->addStatusToHistory($order->getStatus(), $payment->message);
484+
$order->save();
485+
Mage::getSingleton('core/session')->addError($mode ? $payment->message : $payment->technical_message);
486+
$paymentInst->setTransactionId($paymentData['transaction_id']);
487+
return;
488+
}
489+
490+
// And some information aggregation before we leave
491+
492+
if( $payment->shouldRedirect()) {
493+
// ok, WPF session created.
494+
Mage::helper('bithypercharge')->logger('Customer redirected to Hypercharge');
495+
$order->addStatusToHistory($order->getStatus(), Mage::helper('bithypercharge')->__('Customer was redirected to Hypercharge.'));
496+
$order->save();
497+
$paymentInst->setLastTransactionId($paymentData['transaction_id']);
498+
Mage::getSingleton('core/session')->setHyperRedirectUrl($payment->redirect_url);
499+
if ($modelPayment->getConfigData('use_iframe') == 1) {
500+
return Mage::getUrl('bit-hypercharge/wpfredirect/hypercharge');
501+
} elseif ($modelPayment->getConfigData('use_iframe') == 2) {
502+
Mage::getSingleton('core/session')->setHyperReviewRedirect(1);
503+
return false;
504+
} else {
505+
return $payment->redirect_url;
506+
}
507+
} elseif($payment->isPersistentInHypercharge()) {
508+
Mage::helper('bithypercharge')->logger($payment->message . " " . $payment->technical_message);
509+
// payment has been created in hypercharge but something went wrong.
510+
if ($payment->status == 'error') {
511+
$order->addStatusToHistory($order->getStatus(), $payment->message);
512+
$order->save();
513+
Mage::getSingleton('core/session')->addError($mode ? $payment->message : $payment->technical_message);
514+
$paymentInst->setTransactionId($paymentData['transaction_id']);
515+
return;
516+
}
517+
518+
} else {
519+
$order->addStatusToHistory($order->getStatus(), $this->__('Could not initiate WPF'));
520+
$order->save();
521+
Mage::getSingleton('core/session')->addError($this->__('Could not initiate WPF'));
522+
return;
523+
}
524+
} catch(Hypercharge\Errors\ValidationError $e) {
525+
// no payment created in hypercharge because of local pre-validation errors
526+
// show validation errors to customer
527+
// $e->errors is an Array of Hash, format: [ { "property": String , "message" : String }, ... ]
528+
$order->addStatusToHistory($order->getStatus(), "Oops! An error occured! " . implode("<br/>", $e->errors));
479529
$order->save();
480-
Mage::getSingleton('core/session')->addError(
481-
$mode ? $response['message'] : $response['technical_message']);
530+
Mage::getSingleton('core/session')->addError($mode ? $payment->message : $payment->technical_message);
482531
$paymentInst->setTransactionId($paymentData['transaction_id']);
483532
return;
484-
}
485533

486-
// And some information aggregation before we leave
487-
Mage::helper('bithypercharge')->logger('Customer redirected to Hypercharge');
488-
$order->addStatusToHistory($order->getStatus(), $gate->__('Customer was redirected to Hypercharge.'));
489-
$order->save();
490-
$paymentInst->setLastTransactionId($response['transaction_id']);
491-
492-
Mage::getSingleton('core/session')->setHyperRedirectUrl($response['redirect_url']);
493-
if ($modelPayment->getConfigData('use_iframe') == 1) {
494-
return Mage::getUrl('bit-hypercharge/wpfredirect/hypercharge');
495-
} elseif ($modelPayment->getConfigData('use_iframe') == 2) {
496-
Mage::getSingleton('core/session')->setHyperReviewRedirect(1);
497-
return false;
498-
} else {
499-
return $response['redirect_url'];
534+
} catch(Exception $e) {
535+
Mage::helper('bithypercharge')->logger('WPF ERROR: ' . var_export($e->getTraceAsString(), true));
536+
$order->addStatusToHistory($order->getStatus(), "Oops! An error occured! ");
537+
$order->save();
538+
Mage::getSingleton('core/session')->addError("Sorry for the inconvenience! An error occured!");
539+
$paymentInst->setTransactionId($paymentData['transaction_id']);
540+
return;
500541
}
501542
}
502543

@@ -539,29 +580,28 @@ public function wpfResponse($post) {
539580
// Check for existence of data
540581
if (!$hypercharge_channels || !$post || !is_array($post))
541582
return;
542-
if (!($post['wpf_status'] && ($post['wpf_status'] == 'error' || $post['wpf_status'] == 'timeout')))
543-
if (!array_key_exists('signature', $post) || !array_key_exists('payment_transaction_channel_token', $post) || !array_key_exists('payment_transaction_unique_id', $post) || !array_key_exists('wpf_transaction_id', $post) || !array_key_exists('payment_transaction_transaction_type', $post) || !array_key_exists('wpf_unique_id', $post) || !array_key_exists('notification_type', $post))
583+
Mage::log(var_export($post, true), null, "aabb.log");
584+
if (!($post['payment_status'] && ($post['payment_status'] == 'error' || $post['payment_status'] == 'timeout')))
585+
if (!array_key_exists('signature', $post) || !array_key_exists('payment_transaction_channel_token', $post) || !array_key_exists('payment_transaction_unique_id', $post) || !array_key_exists('payment_transaction_id', $post) || !array_key_exists('payment_transaction_transaction_type', $post) || !array_key_exists('payment_unique_id', $post) || !array_key_exists('notification_type', $post))
544586
return;
545587

546588
//Get the information from the POST variables
547589
$signature = $post['signature'];
548590
$trx_channel = $post['payment_transaction_channel_token'];
549591
$trx_id = $post['payment_transaction_unique_id'];
550-
$wpf_trx_id = $post['wpf_transaction_id'];
592+
$wpf_trx_id = $post['payment_transaction_id'];
551593
$trx_type = $post['payment_transaction_transaction_type'];
552-
$wpf_id = $post['wpf_unique_id'];
594+
$wpf_id = $post['payment_unique_id'];
553595
$notification_type = $post['notification_type'];
554596
$wireId = null;
555597
if ($post['wire_reference_id']) {
556598
$wireId = $post['wire_reference_id'];
557599
}
558600

559601
$xml = $gate->getTrxEndXml($wpf_id);
560-
602+
$order_id = substr($wpf_trx_id, 0, strpos($wpf_trx_id, '-'));
561603
try {
562-
$order = Mage::getModel('sales/order')
563-
->loadByIncrementId($wpf_trx_id);
564-
//$order_id = $order->getRealOrderId();
604+
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
565605
} catch (Exception $e) {
566606
Mage::helper('bithypercharge')->logger("\n" . $timestamp
567607
. ' Transaction could not be found in database - '
@@ -577,9 +617,9 @@ public function wpfResponse($post) {
577617
$mode = !$modelPayment->getConfigData('mode');
578618

579619
//Check if error or timeout
580-
if ($post['wpf_status'] && ($post['wpf_status'] == 'error' || $post['wpf_status'] == 'timeout')) {
620+
if ($post['payment_status'] && ($post['payment_status'] == 'error' || $post['payment_status'] == 'timeout')) {
581621
// cancel order
582-
if ($post['wpf_status'] == 'timeout') {
622+
if ($post['payment_status'] == 'timeout') {
583623
$order->getPayment()
584624
->setAdditionalInformation(
585625
'Transaction Status', 'timeout')

app/code/community/GlobalExperts/Hypercharge/Model/Debit.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
* @copyright Copyright (c) 2014 Global Experts GmbH (http://www.globalexperts.ch/)
2424
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
2525
*/
26-
27-
require_once 'Hypercharge/interfaces.php';
28-
require_once 'Hypercharge/errors.php';
29-
require_once 'Hypercharge/logger.php';
3026

3127
class GlobalExperts_Hypercharge_Model_Debit extends GlobalExperts_Hypercharge_Model_Mobile {
3228

app/code/community/GlobalExperts/Hypercharge/Model/Mobile.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
2525
*/
2626

27-
require_once 'Hypercharge/interfaces.php';
28-
require_once 'Hypercharge/errors.php';
29-
require_once 'Hypercharge/logger.php';
30-
3127
class GlobalExperts_Hypercharge_Model_Mobile extends Mage_Payment_Model_Method_Abstract {
3228

3329
const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE';
@@ -120,26 +116,31 @@ public function initialize($paymentAction, $stateObject) {
120116
,$mode
121117
);
122118
$channelToken = $hypercharge_channels[$currency]['channel'];
123-
119+
$amount = sprintf("%.02f", $order->getBaseGrandTotal()) * 100;
124120
// prepare initialize data
125-
$initialize = Hypercharge\Payment::mobile(array(
121+
$paymentData = array(
126122
'currency' => $currency
127-
, 'amount' => sprintf("%.02f", $order->getBaseGrandTotal()) * 100 // in cents
128-
, 'transaction_id' => $order->getRealOrderId() //uniqid(time())
129-
, 'usage' => Mage::app()->getStore()->getName() . ' order authorization'
130-
, 'customer_email' => $order->getCustomerEmail()
131-
, 'customer_phone' => $billing->getTelephone()
132-
, 'notification_url' => Mage::getUrl('bit-hypercharge/notification/response', array('_secure' => true))
133-
, 'billing_address' => array (
123+
, 'amount' => (int)$amount // in cents
124+
, 'transaction_id' => $order->getRealOrderId() //uniqid(time())
125+
, 'usage' => Mage::app()->getStore()->getName() . ' order authorization'
126+
, 'customer_email' => $order->getCustomerEmail()
127+
, 'customer_phone' => $billing->getTelephone()
128+
, 'notification_url' => Mage::getUrl('bit-hypercharge/notification/response', array('_secure' => true))
129+
, 'billing_address' => array(
134130
'first_name' => $billing->getFirstname()
135-
, 'last_name' => $billing->getLastname()
136-
, 'address1' => $billing->getStreet(1)
137-
, 'zip_code' => $billing->getPostcode()
138-
, 'city' => $billing->getCity()
139-
, 'state' => $billing->getRegionCode()
140-
, 'country' => $billing->getCountry()
141-
)
142-
));
131+
, 'last_name' => $billing->getLastname()
132+
, 'address1' => $billing->getStreet(1)
133+
, 'zip_code' => $billing->getPostcode()
134+
, 'city' => $billing->getCity()
135+
, 'country' => $billing->getCountry()
136+
)
137+
);
138+
139+
if (in_array($paymentData['billing_address']['country'], array('US', 'CA'))) {
140+
$paymentData['billing_address']['state'] = $billing->getRegionCode();
141+
};
142+
143+
$initialize = Hypercharge\Payment::mobile($paymentData);
143144
// check if authorization is approved
144145
if ($initialize->unique_id && $initialize->status == 'new' && !$initialize->error) {
145146
Mage::helper('bithypercharge')->logger("Initialize transaction approved");

app/code/community/GlobalExperts/Hypercharge/Model/Mobilepurchaseaccount.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
* @copyright Copyright (c) 2014 Global Experts GmbH (http://www.globalexperts.ch/)
2424
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
2525
*/
26-
27-
require_once 'Hypercharge/interfaces.php';
28-
require_once 'Hypercharge/errors.php';
29-
require_once 'Hypercharge/logger.php';
3026

3127
class GlobalExperts_Hypercharge_Model_Mobilepurchaseaccount extends GlobalExperts_Hypercharge_Model_Mobile {
3228

app/code/community/GlobalExperts/Hypercharge/Model/Sepa.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
* @copyright Copyright (c) 2014 Global Experts GmbH (http://www.globalexperts.ch/)
2424
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
2525
*/
26-
27-
require_once 'Hypercharge/interfaces.php';
28-
require_once 'Hypercharge/errors.php';
29-
require_once 'Hypercharge/logger.php';
3026

3127
class GlobalExperts_Hypercharge_Model_Sepa extends GlobalExperts_Hypercharge_Model_Mobile {
3228

@@ -110,6 +106,7 @@ public function void(Varien_Object $payment) {
110106
} else {
111107
$mode = Hypercharge\Config::ENV_LIVE;
112108
}
109+
113110
// start logging transaction
114111
Mage::helper('bithypercharge')->logger("\n" . str_repeat("*", 80) . "\n Void transaction started");
115112
// get current order

app/code/community/GlobalExperts/Hypercharge/controllers/WpfredirectController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function successAction() {
6363
Mage::getSingleton('checkout/session')->getQuote()
6464
->setIsActive(false)->save();
6565
echo '<script type="text/javascript">window.top.location.href = "' . Mage::getUrl('checkout/onepage/success') . '"; </script>';
66-
//$this->_redirect('checkout/onepage/success');
6766
}
6867

6968
public function failureAction() {
@@ -77,7 +76,6 @@ public function failureAction() {
7776
}
7877
}
7978
echo '<script type="text/javascript">window.top.location.href = "' . Mage::getUrl('checkout/onepage/failure') . '"; </script>';
80-
//$this->_redirect('checkout/onepage/failure');
8179
}
8280

8381
public function cancelAction() {
@@ -91,7 +89,6 @@ public function cancelAction() {
9189
}
9290
}
9391
echo '<script type="text/javascript">window.top.location.href = "' . Mage::getUrl('checkout/onepage/failure') . '"; </script>';
94-
//$this->_redirect('checkout/onepage/failure');
9592
}
9693

9794
/**

app/code/community/GlobalExperts/Hypercharge/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<config>
2929
<modules>
3030
<GlobalExperts_Hypercharge>
31-
<version>1.0.4</version>
31+
<version>1.0.6</version>
3232
</GlobalExperts_Hypercharge>
3333
</modules>
3434

0 commit comments

Comments
 (0)