Version Notes
Add taply payment method
Download this release
Release Info
Developer | taply |
Extension | taply |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/local/Taply/Paybutton/Block/Button/Pay.php +41 -0
- app/code/local/Taply/Paybutton/Helper/Data.php +5 -0
- app/code/local/Taply/Paybutton/Model/Payment.php +38 -0
- app/code/local/Taply/Paybutton/Model/Viewtype.php +60 -0
- app/code/local/Taply/Paybutton/controllers/GetshippingController.php +77 -0
- app/code/local/Taply/Paybutton/controllers/SuccessController.php +174 -0
- app/code/local/Taply/Paybutton/etc/config.xml +49 -0
- app/code/local/Taply/Paybutton/etc/system.xml +52 -0
- app/design/frontend/base/default/layout/taply.xml +12 -0
- app/design/frontend/base/default/template/taply/button.phtml +28 -0
- app/etc/modules/Taply_Paybutton.xml +10 -0
- js/taply/taply.1.1.js +445 -0
- package.xml +18 -0
app/code/local/Taply/Paybutton/Block/Button/Pay.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Taply_Paybutton_Block_Button_Pay extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
public $config =array();
|
5 |
+
|
6 |
+
protected function _construct(){
|
7 |
+
parent::_construct();
|
8 |
+
$this->config = Mage::getStoreConfig('payment/taply');
|
9 |
+
}
|
10 |
+
|
11 |
+
protected function _toHtml(){
|
12 |
+
$isExtensionEnabled = Mage::getStoreConfigFlag('payment/paybutton/active');
|
13 |
+
if (isset($this->config['active']) && $this->config['active']) {
|
14 |
+
return parent::_toHtml();
|
15 |
+
}
|
16 |
+
return '';
|
17 |
+
$result = parent::_beforeToHtml();
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getCartArray(){
|
21 |
+
$arrItems = array();
|
22 |
+
$session= Mage::getSingleton('checkout/session');
|
23 |
+
$quote = $session->getQuote();
|
24 |
+
$cartItems = $quote->getAllVisibleItems();
|
25 |
+
foreach ($cartItems as $item) {
|
26 |
+
$product = $item->getProduct();
|
27 |
+
$arrItems[] = array(
|
28 |
+
'item_prod_id' => $product->getId(),
|
29 |
+
'item_prod_attr' => unserialize($product->getCustomOption('attributes')->getValue()) ,//json_encode( $helper->getOptions($item) ),
|
30 |
+
'item_name' => $product->getName(),
|
31 |
+
'item_img' => (string)Mage::helper('catalog/image')->init($product, 'thumbnail'),
|
32 |
+
'item_description' => Mage::getModel('catalog/product')->load($product->getId())->getShortDescription(),
|
33 |
+
'item_qty' => $item->getQty(),
|
34 |
+
'item_price' => $product->getPrice(),
|
35 |
+
);
|
36 |
+
}
|
37 |
+
|
38 |
+
return array('merchant' => $this->config['merchant_id'],'description' => $this->config['description'],'currency'=>'USD','items' => $arrItems);
|
39 |
+
|
40 |
+
}
|
41 |
+
}
|
app/code/local/Taply/Paybutton/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Taply_Paybutton_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
5 |
+
|
app/code/local/Taply/Paybutton/Model/Payment.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Used in creating options for Yes|No config value selection
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Taply_Paybutton_Model_Payment extends Mage_Payment_Model_Method_Abstract
|
32 |
+
{
|
33 |
+
protected $_code = 'taply';
|
34 |
+
|
35 |
+
public function getTitle(){
|
36 |
+
return 'Taply';
|
37 |
+
}
|
38 |
+
}
|
app/code/local/Taply/Paybutton/Model/Viewtype.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Used in creating options for Yes|No config value selection
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Taply_Paybutton_Model_Viewtype
|
32 |
+
{
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Options getter
|
36 |
+
*
|
37 |
+
* @return array
|
38 |
+
*/
|
39 |
+
public function toOptionArray()
|
40 |
+
{
|
41 |
+
return array(
|
42 |
+
array('value' => 'popup' , 'label'=>Mage::helper('adminhtml')->__('with Popup window')),
|
43 |
+
array('value' => 'block', 'label'=>Mage::helper('adminhtml')->__('single block')),
|
44 |
+
);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Get options in "key-value" format
|
49 |
+
*
|
50 |
+
* @return array
|
51 |
+
*/
|
52 |
+
public function toArray()
|
53 |
+
{
|
54 |
+
return array(
|
55 |
+
'popup' => Mage::helper('adminhtml')->__('with Popup window'),
|
56 |
+
'block' => Mage::helper('adminhtml')->__('single block'),
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
app/code/local/Taply/Paybutton/controllers/GetshippingController.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Taply_Paybutton_GetshippingController extends Mage_Core_Controller_Front_Action{
|
3 |
+
|
4 |
+
public function indexAction()
|
5 |
+
{
|
6 |
+
$store = Mage::app()->getStore();
|
7 |
+
$objCart = Mage::getModel('sales/quote')->setStoreId($store->getId());
|
8 |
+
$objCart->setCustomer(Mage::getModel('customer/customer'));
|
9 |
+
$country = (string) $this->getRequest()->getParam('country_id');
|
10 |
+
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
|
11 |
+
$city = (string) $this->getRequest()->getParam('estimate_city');
|
12 |
+
$region = (string) $this->getRequest()->getParam('region');
|
13 |
+
$itemsJson = (string) $this->getRequest()->getParam('items');
|
14 |
+
$items = Mage::helper('core')->jsonDecode($itemsJson);
|
15 |
+
$regionModel = Mage::getModel('directory/region')->loadByCode($region, $country);
|
16 |
+
$regionId = $regionModel->getId();
|
17 |
+
|
18 |
+
try{
|
19 |
+
foreach ($items as $item){
|
20 |
+
$product = Mage::getModel('catalog/product')->load($item['item_prod_id']);
|
21 |
+
$product->setPrice($item['item_price']);
|
22 |
+
$product->addCustomOption('attributes', serialize($item['item_prod_attr']));
|
23 |
+
$request = new Varien_Object();
|
24 |
+
$request->setQty($item['item_qty']);
|
25 |
+
$request->setSuperAttribute($item['item_prod_attr']);
|
26 |
+
if ($product->getId()) {
|
27 |
+
// Add product to card
|
28 |
+
$result = $objCart->addProduct($product, $request);
|
29 |
+
if (is_string($result)) {
|
30 |
+
// Error of adding product to card
|
31 |
+
// @todo Log exception into DB and skip
|
32 |
+
throw new Exception($result);
|
33 |
+
}
|
34 |
+
} else {
|
35 |
+
// Error of load product by id
|
36 |
+
throw new Exception("Cant load product");
|
37 |
+
// @todo Log exception into DB and skip
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
$sa = $objCart->getShippingAddress();
|
43 |
+
$sa->setCountryId($country)
|
44 |
+
->setCity($city)
|
45 |
+
->setPostcode($postcode)
|
46 |
+
->setRegionId($regionId)
|
47 |
+
->setRegion($region)
|
48 |
+
->setCollectShippingRates(TRUE)->save();
|
49 |
+
// var_dump($sa->toArray());
|
50 |
+
} catch (Exception $e){
|
51 |
+
die($e->getMessage());
|
52 |
+
}
|
53 |
+
|
54 |
+
$objCart->save();
|
55 |
+
|
56 |
+
$objCart->collectTotals();
|
57 |
+
$objCart->save();
|
58 |
+
|
59 |
+
$quoteData= $sa->getData();
|
60 |
+
$arrShipping=array("shippings" => array(), "tax" => $quoteData['tax_amount']);
|
61 |
+
foreach ($sa->getGroupedAllShippingRates() as $strCode => $arrRates ){
|
62 |
+
foreach ($arrRates as $objRate){
|
63 |
+
$name = Mage::getStoreConfig('carriers/'.$strCode.'/title');
|
64 |
+
$strCarrierName = $name? $name : strtoupper($strCode);
|
65 |
+
$arrShipping["shippings"][] = array(
|
66 |
+
"identifier" => $objRate->getCode(),
|
67 |
+
"label" => $strCarrierName . " " . $objRate->getMethodTitle(),
|
68 |
+
"amount" => $objRate->getPrice(),
|
69 |
+
"detail" => $strCarrierName . " " . $objRate->getMethodTitle() . ", $" . $objRate->getPrice()
|
70 |
+
);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
echo Mage::helper('core')->jsonEncode($arrShipping);
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
}
|
app/code/local/Taply/Paybutton/controllers/SuccessController.php
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Taply_Paybutton_SuccessController extends Mage_Core_Controller_Front_Action{
|
3 |
+
const TAPLY_API_URL = "https://api.paybytaply.com/payment/";
|
4 |
+
|
5 |
+
|
6 |
+
protected $_methodType = 'taply';
|
7 |
+
|
8 |
+
protected function _callApiMethod($strMethod, $arrParams = array()){
|
9 |
+
|
10 |
+
$arrResponse = array();
|
11 |
+
$process = curl_init(self::TAPLY_API_URL . $strMethod);
|
12 |
+
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
|
13 |
+
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
|
14 |
+
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, false);
|
15 |
+
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
|
16 |
+
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
|
17 |
+
if (!empty($arrParams)){
|
18 |
+
curl_setopt($process, CURLOPT_POST, 1);
|
19 |
+
curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($arrParams));
|
20 |
+
}
|
21 |
+
$strResponseJson = curl_exec( $process );
|
22 |
+
curl_close($process);
|
23 |
+
if($strResponseJson){
|
24 |
+
$arrResponse = json_decode( $strResponseJson, TRUE );
|
25 |
+
|
26 |
+
}
|
27 |
+
return $arrResponse;
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
public function indexAction()
|
32 |
+
{
|
33 |
+
$_params = $this->getRequest()->getParams();
|
34 |
+
$config = Mage::getStoreConfig('payment/taply');
|
35 |
+
$arrResponse = $this->_callApiMethod('get-payment-info', array('payment' => $_params['payment'], 'merchantid' => $config['merchant_id'] ));
|
36 |
+
|
37 |
+
if(!isset($arrResponse['result']['cart'])){
|
38 |
+
echo json_encode(array('error' => 'Carts not matched'));
|
39 |
+
exit();
|
40 |
+
}
|
41 |
+
$sOrderCartJson = $arrResponse['result']['cart'];
|
42 |
+
$sOrderTransaction = $arrResponse['result']['transaction'];
|
43 |
+
$arrOrderCart = json_decode($sOrderCartJson, TRUE);
|
44 |
+
$arrOrderTransaction = json_decode( $sOrderTransaction, TRUE);
|
45 |
+
if(isset($arrResponse['result']['order_id']) && $arrResponse['result']['order_id']){
|
46 |
+
$order = Mage::getModel('sales/order')->load($arrResponse['result']['order_id']);
|
47 |
+
if($order->getId()){
|
48 |
+
echo json_encode( array('order_id' => $order->getId(), 'redirect_url' => Mage::getUrl() . '/taply/success/thanks/order/' . $order->getId()) );
|
49 |
+
exit;
|
50 |
+
}
|
51 |
+
}
|
52 |
+
try{
|
53 |
+
|
54 |
+
$store = Mage::app()->getStore();
|
55 |
+
$quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
|
56 |
+
|
57 |
+
$aUser = $arrOrderTransaction['user_info'];
|
58 |
+
$objCustomer = Mage::getModel('customer/customer');
|
59 |
+
$websiteId = Mage::app()->getWebsite()->getId();
|
60 |
+
$objCustomer->setWebsiteId($websiteId)->setStore($store);
|
61 |
+
|
62 |
+
foreach ($arrOrderCart['items'] as $item){
|
63 |
+
|
64 |
+
$product = Mage::getModel('catalog/product')->load($item['item_prod_id']);
|
65 |
+
$product->setPrice($item['item_price']);
|
66 |
+
$product->addCustomOption('attributes', serialize($item['item_prod_attr']));
|
67 |
+
$request = new Varien_Object();
|
68 |
+
$request->setQty($item['item_qty']);
|
69 |
+
$request->setSuperAttribute($item['item_prod_attr']);
|
70 |
+
if ($product->getId()) {
|
71 |
+
// Add product to card
|
72 |
+
$result = $quote->addProduct($product, $request);
|
73 |
+
if (is_string($result)) {
|
74 |
+
// Error of adding product to card
|
75 |
+
// @todo Log exception into DB and skip
|
76 |
+
throw new Exception($result);
|
77 |
+
}
|
78 |
+
} else {
|
79 |
+
// Error of load product by id
|
80 |
+
throw new Exception("Cant load product");
|
81 |
+
// @todo Log exception into DB and skip
|
82 |
+
}
|
83 |
+
}
|
84 |
+
if(isset($aUser['billingAddress']['email'])){
|
85 |
+
$objCustomer->loadByEmail($aUser['billingAddress']['email']);
|
86 |
+
if (!$objCustomer->getId()){
|
87 |
+
$objCustomer->setFirstname($aUser['billingAddress']['firstName'])
|
88 |
+
->setLastname($aUser['billingAddress']['lastName'])
|
89 |
+
->setEmail($aUser['billingAddress']['email'])
|
90 |
+
->setPassword($customer->generatePassword(7));
|
91 |
+
|
92 |
+
|
93 |
+
try{
|
94 |
+
$objCustomer->save();
|
95 |
+
$objCustomer->setConfirmation(null); //confirmation needed to register
|
96 |
+
$objCustomer->save(); //yes, this is also needed
|
97 |
+
$objCustomer->sendNewAccountEmail(); //send confirmation email to customer
|
98 |
+
|
99 |
+
// $newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
|
100 |
+
// $objCustomer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
|
101 |
+
// $objCustomer->sendPasswordResetConfirmationEmail();
|
102 |
+
}
|
103 |
+
catch (Exception $e) {
|
104 |
+
Zend_Debug::dump($e->getMessage());
|
105 |
+
}
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
$quote->setCustomer($objCustomer);
|
110 |
+
Mage::getSingleton('customer/session')->loginById($objCustomer->getId());
|
111 |
+
|
112 |
+
$billingAddress = array(
|
113 |
+
'firstname' => $aUser['billingAddress']['firstName'],
|
114 |
+
'lastname' => $aUser['billingAddress']['lastName'],
|
115 |
+
'email' => $aUser['billingAddress']['email'],
|
116 |
+
'country_id' => $aUser['billingAddress']['country'],
|
117 |
+
'region' => $aUser['billingAddress']['state'],
|
118 |
+
'postcode' => $aUser['billingAddress']['zip'],
|
119 |
+
'street' => $aUser['billingAddress']['street1'], //array( $aUser['billingAddress']['street1'], $aUser['billingAddress']['street2'] ),
|
120 |
+
'city' => $aUser['billingAddress']['city'],
|
121 |
+
'telephone' => $aUser['billingAddress']['phone'],
|
122 |
+
'save_in_address_book' => 0,
|
123 |
+
);
|
124 |
+
$shippingAddressData = array(
|
125 |
+
'firstname' => $aUser['shippingAddress']['firstName'],
|
126 |
+
'lastname' => $aUser['shippingAddress']['lastName'],
|
127 |
+
'email' => $aUser['shippingAddress']['email'],
|
128 |
+
'country_id' => $aUser['shippingAddress']['country'],
|
129 |
+
'region' => $aUser['shippingAddress']['state'],
|
130 |
+
'postcode' => $aUser['shippingAddress']['zip'],
|
131 |
+
'street' => $aUser['shippingAddress']['street1'], //array( $aUser['shippingAddress']['street1'], $aUser['shippingAddress']['street2'] ),
|
132 |
+
'city' => $aUser['shippingAddress']['city'],
|
133 |
+
'telephone' => $aUser['shippingAddress']['phone'],
|
134 |
+
'save_in_address_book' => 0,
|
135 |
+
);
|
136 |
+
|
137 |
+
if(isset($arrResponse['result']['shipping']['identifier']) && strpos(strtolower($arrResponse['result']['shipping']['identifier']), "free") === FALSE){
|
138 |
+
$shippingMethod = $arrResponse['result']['shipping']['identifier'];
|
139 |
+
}else{
|
140 |
+
$shippingMethod = 'freeshipping_freeshipping';
|
141 |
+
}
|
142 |
+
$quote->getBillingAddress()->addData($billingAddress);
|
143 |
+
$quote->getShippingAddress()
|
144 |
+
->addData($shippingAddressData)
|
145 |
+
->setShippingMethod($shippingMethod)
|
146 |
+
->setPaymentMethod($this->_methodType)
|
147 |
+
->setCollectShippingRates(true)
|
148 |
+
->collectTotals();
|
149 |
+
$quote->getPayment()->importData(array('method' => $this->_methodType));
|
150 |
+
$quote->collectTotals()->save();
|
151 |
+
$service = Mage::getModel('sales/service_quote', $quote);
|
152 |
+
$service->submitAll();
|
153 |
+
$lastOrderId = $service->getOrder()->getId();
|
154 |
+
|
155 |
+
unset($quote);
|
156 |
+
unset($objCustomer);
|
157 |
+
unset($service);
|
158 |
+
echo json_encode( array('order_id' => $lastOrderId, 'redirect_url' => Mage::getUrl() . '/taply/success/thanks/order/' . $lastOrderId) );
|
159 |
+
|
160 |
+
} catch (Exception $e){
|
161 |
+
$quote = $customer = $service = null;
|
162 |
+
echo json_encode( array('error' => $e->getMessage()) );
|
163 |
+
}
|
164 |
+
|
165 |
+
}
|
166 |
+
|
167 |
+
public function thanksAction()
|
168 |
+
{
|
169 |
+
Mage::getSingleton('checkout/cart')->truncate()->save();
|
170 |
+
$_params = $this->getRequest()->getParams();
|
171 |
+
$this->_redirect('sales/order/view/', array('order_id' => $_params['order']));
|
172 |
+
|
173 |
+
}
|
174 |
+
}
|
app/code/local/Taply/Paybutton/etc/config.xml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Taply_Paybutton>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Taply_Paybutton>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<taply>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>Taply_Paybutton</module>
|
14 |
+
<frontName>taply</frontName>
|
15 |
+
</args>
|
16 |
+
</taply>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<taply>
|
21 |
+
<file>taply.xml</file>
|
22 |
+
</taply>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
</frontend>
|
26 |
+
|
27 |
+
<global>
|
28 |
+
<models>
|
29 |
+
<paybutton>
|
30 |
+
<class>Taply_Paybutton_Model</class>
|
31 |
+
<resourceModel>viewtype</resourceModel>
|
32 |
+
<resourceModel>payment</resourceModel>
|
33 |
+
</paybutton>
|
34 |
+
</models>
|
35 |
+
<blocks>
|
36 |
+
<paybutton>
|
37 |
+
<class>Taply_Paybutton_Block</class>
|
38 |
+
</paybutton>
|
39 |
+
</blocks>
|
40 |
+
</global>
|
41 |
+
<default>
|
42 |
+
<payment>
|
43 |
+
<taply>
|
44 |
+
<active>1</active>
|
45 |
+
<model>paybutton/payment</model>
|
46 |
+
</taply>
|
47 |
+
</payment>
|
48 |
+
</default>
|
49 |
+
</config>
|
app/code/local/Taply/Paybutton/etc/system.xml
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<taply translate="label">
|
7 |
+
<label>Pay By Taply</label>
|
8 |
+
<sort_order>770</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<fields>
|
13 |
+
<active translate="label">
|
14 |
+
<label>Enabled</label>
|
15 |
+
<frontend_type>select</frontend_type>
|
16 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
17 |
+
<sort_order>100</sort_order>
|
18 |
+
<show_in_default>1</show_in_default>
|
19 |
+
<show_in_website>1</show_in_website>
|
20 |
+
<show_in_store>0</show_in_store>
|
21 |
+
</active>
|
22 |
+
<merchant_id>
|
23 |
+
<label>Taply Store ID</label>
|
24 |
+
<frontend_type>text</frontend_type>
|
25 |
+
<sort_order>101</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>1</show_in_website>
|
28 |
+
<show_in_store>0</show_in_store>
|
29 |
+
</merchant_id>
|
30 |
+
<description>
|
31 |
+
<label>Description</label>
|
32 |
+
<frontend_type>text</frontend_type>
|
33 |
+
<sort_order>102</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>0</show_in_store>
|
37 |
+
</description>
|
38 |
+
<view_type>
|
39 |
+
<label>View Type</label>
|
40 |
+
<frontend_type>select</frontend_type>
|
41 |
+
<source_model>paybutton/viewtype</source_model>
|
42 |
+
<sort_order>103</sort_order>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<show_in_website>1</show_in_website>
|
45 |
+
<show_in_store>0</show_in_store>
|
46 |
+
</view_type>
|
47 |
+
</fields>
|
48 |
+
</taply>
|
49 |
+
</groups>
|
50 |
+
</payment>
|
51 |
+
</sections>
|
52 |
+
</config>
|
app/design/frontend/base/default/layout/taply.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<layout version="0.1.0">
|
2 |
+
<checkout_cart_index>
|
3 |
+
<reference name="checkout.cart.methods">
|
4 |
+
<block type="paybutton/button_pay" name="checkout.cart.methods.paybytaply.bottom" before="-" template="taply/button.phtml">
|
5 |
+
<action method="setIsQuoteAllowed"><value>1</value></action>
|
6 |
+
</block>
|
7 |
+
</reference>
|
8 |
+
<reference name="head">
|
9 |
+
<action method="addItem"><type>js</type><name>taply/taply.1.1.js</name></action>
|
10 |
+
</reference>
|
11 |
+
</checkout_cart_index>
|
12 |
+
</layout>
|
app/design/frontend/base/default/template/taply/button.phtml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$config = Mage::getStoreConfig('payment/paybutton');
|
3 |
+
$arrCart = $this->getCartArray();
|
4 |
+
|
5 |
+
?>
|
6 |
+
|
7 |
+
<?php if(isset($this->config['view_type']) && $this->config['view_type'] == 'block'): ?>
|
8 |
+
<div class="module pay-module taply-block" data-type="cart" data-view-type="block" data-cart="<?php echo htmlspecialchars(json_encode($arrCart), ENT_QUOTES, 'UTF-8'); ?>">
|
9 |
+
<h4>Have Apply Pay?</h4>
|
10 |
+
<div class="field opt note"></div>
|
11 |
+
<div class="field text">
|
12 |
+
<label class="scr-only" for="phone">Phone number</label>
|
13 |
+
<input class="input-text" id="phone" name="phone" type="tel">
|
14 |
+
</div>
|
15 |
+
<div class="field opt">
|
16 |
+
<input class="input-checkbox" id="save-phone-number-1" name="save-phone" type="checkbox">
|
17 |
+
<label for="save-phone-number-1">Save phone number</label>
|
18 |
+
</div>
|
19 |
+
<a class="taply-apply-pay taply-btn" href="/">Pay by taply using Apple Pay</a>
|
20 |
+
<p>Use the <a href="https://www.paybytaply.com/app">mobile app</a> to pay</p>
|
21 |
+
</div>
|
22 |
+
<?php else : ?>
|
23 |
+
<div class="module pay-module taply-block" data-type="cart" data-cart="<?php echo htmlspecialchars(json_encode($arrCart), ENT_QUOTES, 'UTF-8'); ?>">
|
24 |
+
<h4>Have Apply Pay?</h4>
|
25 |
+
<a class="taply-apply-pay taply-btn" href="/">Pay by taply using Apple Pay</a>
|
26 |
+
<p>Use the <a href="https://www.paybytaply.com/app">mobile app</a> to pay</p>
|
27 |
+
</div>
|
28 |
+
<?php endif; ?>
|
app/etc/modules/Taply_Paybutton.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Taply_Paybutton>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</Taply_Paybutton>
|
9 |
+
</modules>
|
10 |
+
</config>
|
js/taply/taply.1.1.js
ADDED
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function(w,d) {
|
2 |
+
function transitionSelect() {
|
3 |
+
var el = d.createElement("div");
|
4 |
+
if (el.style.WebkitTransition) return "webkitTransitionEnd";
|
5 |
+
if (el.style.OTransition) return "oTransitionEnd";
|
6 |
+
return 'transitionend';
|
7 |
+
};
|
8 |
+
|
9 |
+
w.TaplyDlg = {
|
10 |
+
options: {
|
11 |
+
dialogContent: '<div class="dialog-header"><div><h4 class="modal-title taply-title">taply</h4></div></div><div class="dialog-body"><div><p>Please enter your mobile phone number to complete your payment</p><div class="input-field text-field "><input class="phone" name="phone" type="tel" value=""/></div><div class="input-field checkbox-field"><input class="save-phone" type="checkbox" id="save-mobile-number" value="save-mobile-number"/> <label for="save-mobile-number">Save mobile phone number</label></div></div></div><div class="dialog-footer"><div><button class="btn pay">Pay</button></div></div>',
|
12 |
+
autoOpen: false,
|
13 |
+
className: 'taply-dialog',
|
14 |
+
closeBtn: true,
|
15 |
+
content: "",
|
16 |
+
maxWidth: 360,
|
17 |
+
minWidth: 280,
|
18 |
+
overlay: true
|
19 |
+
},
|
20 |
+
savedPhone: '',
|
21 |
+
initialized: false,
|
22 |
+
modal: null,
|
23 |
+
overlay: null,
|
24 |
+
closeBtn: null,
|
25 |
+
transitionEnd: transitionSelect(),
|
26 |
+
init: function(){
|
27 |
+
if(w.TaplyDlg.phone) return;
|
28 |
+
var t = w.TaplyDlg,dF = d.createDocumentFragment(),cH;
|
29 |
+
if(t.overlay && t.overlay.parentNode) t.overlay.parentNode.removeChild(t.overlay);
|
30 |
+
if(t.modal && t.modal.parentNode) t.modal.parentNode.removeChild(t.modal);
|
31 |
+
|
32 |
+
if (t.options.overlay === true) {
|
33 |
+
t.overlay = d.createElement("div");
|
34 |
+
t.overlay.className = "taply-modal-overlay " + t.options.className;
|
35 |
+
dF.appendChild(this.overlay);
|
36 |
+
}
|
37 |
+
// create modal element
|
38 |
+
t.modal = d.createElement("div");
|
39 |
+
t.modal.className = "taply-modal " + t.options.className;
|
40 |
+
t.modal.style.minWidth = t.options.minWidth + "px";
|
41 |
+
t.modal.style.maxWidth = t.options.maxWidth + "px";
|
42 |
+
|
43 |
+
// create content area
|
44 |
+
cH = d.createElement("div");
|
45 |
+
cH.className = "taply-modal-window";
|
46 |
+
cH.innerHTML = t.options.dialogContent;
|
47 |
+
t.content = cH;
|
48 |
+
// if closeBtn option is true, build a close button, append close button and content to area
|
49 |
+
if (t.options.closeBtn === true) {
|
50 |
+
t.closeBtn = d.createElement("button");
|
51 |
+
t.closeBtn.className = "taply-modal-close pay-later";
|
52 |
+
t.closeBtn.innerHTML = "Close";
|
53 |
+
|
54 |
+
t.modal.appendChild(cH).appendChild(t.closeBtn);
|
55 |
+
|
56 |
+
} else {
|
57 |
+
// append content to area
|
58 |
+
this.modal.appendChild(cH);
|
59 |
+
|
60 |
+
}
|
61 |
+
|
62 |
+
// append modal to DocumentFragment
|
63 |
+
dF.appendChild(t.modal);
|
64 |
+
|
65 |
+
// append DocumentFragment to body
|
66 |
+
d.body.appendChild(dF);
|
67 |
+
var ps = t.modal.getElementsByTagName("input");
|
68 |
+
for ( var p=0;p<ps.length;p++ ){
|
69 |
+
if(ps[p].type == 'tel' || ps[p].type == 'text'){
|
70 |
+
ps[p].addEventListener('keydown', w.Taply.check.bind(t.current), false);
|
71 |
+
ps[p].module = t.current;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
t.initializeEvents();
|
75 |
+
|
76 |
+
w.TaplyDlg.initialized = true;
|
77 |
+
},
|
78 |
+
|
79 |
+
send: function(){
|
80 |
+
w.Taply.send(w.TaplyDlg.current);
|
81 |
+
},
|
82 |
+
payLater: function(){
|
83 |
+
w.Taply.payLater(w.TaplyDlg.current);
|
84 |
+
w.TaplyDlg.close();
|
85 |
+
},
|
86 |
+
|
87 |
+
cancel: function(){
|
88 |
+
w.Taply.cancel(w.TaplyDlg.current);
|
89 |
+
w.TaplyDlg.close();
|
90 |
+
},
|
91 |
+
tryagain: function(){
|
92 |
+
w.TaplyDlg.open(w.TaplyDlg.current);
|
93 |
+
},
|
94 |
+
close: function() {
|
95 |
+
var t = w.TaplyDlg;
|
96 |
+
t.modal.className = t.modal.className.replace(" taply-modal-open", "");
|
97 |
+
t.overlay.className = t.overlay.className.replace(" taply-modal-overlay-open","");
|
98 |
+
},
|
99 |
+
open: function(block) {
|
100 |
+
|
101 |
+
var t = w.TaplyDlg;
|
102 |
+
t.current = block;
|
103 |
+
t.init();
|
104 |
+
t.current.phone = t.content.getElementsByClassName('phone')[0];
|
105 |
+
t.current.phone.module = block;
|
106 |
+
t.current.save_phone = t.content.getElementsByClassName('save-phone')[0];
|
107 |
+
if(w.Taply.savedPhone !== undefined && t.current.phone.value==''){
|
108 |
+
t.current.phone.value=w.Taply.savedPhone;
|
109 |
+
t.current.save_phone.checked = 1;
|
110 |
+
}
|
111 |
+
w.getComputedStyle(t.modal).height;
|
112 |
+
t.modal.className = t.modal.className + " taply-modal-open";
|
113 |
+
t.overlay.className = t.overlay.className + " taply-modal-overlay-open";
|
114 |
+
},
|
115 |
+
initializeEvents: function(){
|
116 |
+
var t = w.TaplyDlg;
|
117 |
+
var closeBtns = d.getElementsByClassName("close-modal");
|
118 |
+
if (closeBtns) {
|
119 |
+
for(var i=0;i<closeBtns.length;i++){
|
120 |
+
closeBtns[i].addEventListener('click', t.cancel.bind(t), false);
|
121 |
+
}
|
122 |
+
|
123 |
+
}
|
124 |
+
|
125 |
+
if (this.overlay) {
|
126 |
+
this.overlay.addEventListener('click', t.close.bind(t));
|
127 |
+
}
|
128 |
+
|
129 |
+
var payBtns = t.content.getElementsByClassName("btn pay");
|
130 |
+
if(payBtns.length){
|
131 |
+
payBtns[0].addEventListener('click', t.send.bind(t), false);
|
132 |
+
}
|
133 |
+
|
134 |
+
var payLaterBtns = t.modal.getElementsByClassName("pay-later");
|
135 |
+
if(payLaterBtns.length){
|
136 |
+
payLaterBtns[0].addEventListener('click', t.payLater.bind(t), false);
|
137 |
+
}
|
138 |
+
|
139 |
+
var tryAgainBtns = t.content.getElementsByClassName("btn try-again");
|
140 |
+
if(tryAgainBtns.length){
|
141 |
+
tryAgainBtns[0].addEventListener('click', t.tryagain.bind(t), false);
|
142 |
+
}
|
143 |
+
},
|
144 |
+
changeContent: function(c){
|
145 |
+
var b = w.TaplyDlg.content.getElementsByClassName('dialog-body')[0],n='Unknown error', f= '';
|
146 |
+
switch(c){
|
147 |
+
case 0:
|
148 |
+
n= '<div><p>' + (w.Taply.notifyMessages[c] ? w.Taply.notifyMessages[c] : n) + '</p></div>';
|
149 |
+
f='<div><button class="btn try-again">Try again</button></div>';
|
150 |
+
break;
|
151 |
+
case 1:
|
152 |
+
n='<div><div class="loader">Loading</div><p>' + w.Taply.notifyMessages[c] + '</p></div>';
|
153 |
+
f='<div><button class="btn pay-later">Pay later</button><button class="btn btn-alt close-modal">Cancel</button></div>'
|
154 |
+
break;
|
155 |
+
default :
|
156 |
+
n= '<div><p>' + (w.Taply.notifyMessages[c] ? w.Taply.notifyMessages[c] : n) + '</p></div>';
|
157 |
+
}
|
158 |
+
w.TaplyDlg.content.getElementsByClassName('dialog-footer')[0].innerHTML = f;
|
159 |
+
b.innerHTML = n;
|
160 |
+
w.TaplyDlg.initializeEvents();
|
161 |
+
}
|
162 |
+
};
|
163 |
+
w.TaplyModule = function(el,id){
|
164 |
+
var t=this;
|
165 |
+
t.id=id;
|
166 |
+
t.el = el;
|
167 |
+
t.type = el.attributes['data-type'] ? el.attributes['data-type'].value : 'item'; // (item, cart, auto)
|
168 |
+
|
169 |
+
t.phone = null;
|
170 |
+
t.save_phone = null;
|
171 |
+
t.view_type = el.attributes['data-view-type'] ? el.attributes['data-view-type'].value : 'popup';
|
172 |
+
|
173 |
+
switch(t.view_type){
|
174 |
+
case 'block':
|
175 |
+
var ps = el.getElementsByTagName('input');
|
176 |
+
if(ps.length){
|
177 |
+
for(var p=0;p<ps.length;p++){
|
178 |
+
if(ps[p].name == 'phone'){
|
179 |
+
t.phone = t.phone === null? ps[p] : t.phone;
|
180 |
+
ps[p].addEventListener('keydown', w.Taply.check.bind(t), false);
|
181 |
+
ps[p].module = t;
|
182 |
+
}
|
183 |
+
if(ps[p].name == 'save-phone'){
|
184 |
+
t.save_phone = ps[p];
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
break;
|
190 |
+
case 'popup':
|
191 |
+
if(w.Taply.dlg_css === undefined){
|
192 |
+
w.Taply.dlg_css=document.createElement("link");
|
193 |
+
w.Taply.dlg_css.setAttribute("rel", "stylesheet");
|
194 |
+
w.Taply.dlg_css.setAttribute("type", "text/css");
|
195 |
+
w.Taply.dlg_css.setAttribute("href", "//www.paybytaply.com/css/taply-dialog.css");
|
196 |
+
d.getElementsByTagName("head")[0].appendChild(w.Taply.dlg_css);
|
197 |
+
}
|
198 |
+
break;
|
199 |
+
}
|
200 |
+
t.btn = el.getElementsByClassName('taply-btn');
|
201 |
+
if(t.btn.length){
|
202 |
+
t.btn[0].onclick = function(e){
|
203 |
+
switch(t.view_type){
|
204 |
+
case 'block':
|
205 |
+
w.Taply.send(t);
|
206 |
+
break;
|
207 |
+
case 'popup':
|
208 |
+
w.TaplyDlg.open(t);
|
209 |
+
break;
|
210 |
+
}
|
211 |
+
return false;
|
212 |
+
}
|
213 |
+
}
|
214 |
+
t.notify = function(n){
|
215 |
+
var txt = w.Taply.notifyMessages[n];
|
216 |
+
switch(t.view_type){
|
217 |
+
case 'block':
|
218 |
+
var ps = t.el.getElementsByClassName('note');
|
219 |
+
if(ps.length){
|
220 |
+
ps[0].innerHTML = '<p>' + txt + '</p>';
|
221 |
+
}
|
222 |
+
break;
|
223 |
+
case 'popup':
|
224 |
+
w.TaplyDlg.changeContent(n);
|
225 |
+
break;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
};
|
229 |
+
w.Taply = {
|
230 |
+
apiurl: "https://api.paybytaply.com/payment",
|
231 |
+
btnClass: 'taply-block',
|
232 |
+
modules: [],
|
233 |
+
mask: '(___) ___-____',
|
234 |
+
notifies:{
|
235 |
+
invalidPhone:0,
|
236 |
+
complete:1,
|
237 |
+
firstTime:2,
|
238 |
+
notInstall:3,
|
239 |
+
serverError:4
|
240 |
+
},
|
241 |
+
notifyMessages:{
|
242 |
+
'-3': "Your transaction has been refunded.",
|
243 |
+
'-2': "Your transaction has been deleted.",
|
244 |
+
'-1': "Your transaction has been canceled.",
|
245 |
+
'0' :'Please enter a valid phone number.',
|
246 |
+
'1' :'Please complete your payment on your taply mobile app.',
|
247 |
+
'2' :'Good news! Save $10 off your first taply transaction. Please download the taply app using the link texted to your mobile phone.',
|
248 |
+
'3' :'Please download the taply app using the link texted to your mobile phone.',
|
249 |
+
'4' :'Unknown error.',
|
250 |
+
'10': "Your transaction has been pending.",
|
251 |
+
'11': "Your transaction has been approved.",
|
252 |
+
'12': "Your order has been sent to your taply mobile app for checkout at a later time."
|
253 |
+
},
|
254 |
+
ls: function (url,f){
|
255 |
+
var h = d.getElementsByTagName("head")[0] || d.documentElement;
|
256 |
+
var s = d.createElement("script");
|
257 |
+
s.src = url;
|
258 |
+
s.onload = s.onreadystatechange = f;
|
259 |
+
h.insertBefore( s, h.firstChild );
|
260 |
+
},
|
261 |
+
format: function(p){
|
262 |
+
var s='',k=0,m=w.Taply.mask;
|
263 |
+
if(p.length){
|
264 |
+
for(var i=0;i<m.length;i++){
|
265 |
+
if(m[i] != '_'){
|
266 |
+
s+=m[i];
|
267 |
+
}else{
|
268 |
+
if(p[k]){
|
269 |
+
s+= p[k++];
|
270 |
+
}else{
|
271 |
+
break;
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
}
|
276 |
+
return s;
|
277 |
+
},
|
278 |
+
check: function(e){
|
279 |
+
var k = e.keyCode || e.charCode;
|
280 |
+
|
281 |
+
if(!e.ctrlKey && !(k > 47 && k < 58) && k != 8){
|
282 |
+
e.preventDefault();
|
283 |
+
}
|
284 |
+
|
285 |
+
var v=this.phone.value,p=parseInt( v.replace(/[^\d]/g,'') ,10);
|
286 |
+
p=isNaN(p)? '' : p.toString();
|
287 |
+
switch(e.keyCode){
|
288 |
+
case 13:
|
289 |
+
w.Taply.send(this);
|
290 |
+
break;
|
291 |
+
case 8:
|
292 |
+
return true;
|
293 |
+
case 46:
|
294 |
+
p = p.substr(0,p.length-1);
|
295 |
+
break;
|
296 |
+
default :
|
297 |
+
var c = String.fromCharCode(e.keyCode);
|
298 |
+
if(e.keyCode > 47 && e.keyCode < 58){
|
299 |
+
p = p + c;
|
300 |
+
}else if(e.keyCode > 95 && e.keyCode < 106){
|
301 |
+
p = p + (e.keyCode-96);
|
302 |
+
}else{
|
303 |
+
return false;
|
304 |
+
}
|
305 |
+
}
|
306 |
+
this.phone.value = w.Taply.format(p);
|
307 |
+
e.preventDefault();
|
308 |
+
return false;
|
309 |
+
},
|
310 |
+
init: function(){
|
311 |
+
w.Taply.ls(w.Taply.apiurl + '/start?callback=Taply.initValues');
|
312 |
+
var tbs = d.getElementsByClassName(w.Taply.btnClass);
|
313 |
+
for(var i=0; i<tbs.length; i++){
|
314 |
+
w.Taply.modules.push(new w.TaplyModule(tbs[i],w.Taply.modules.length) );
|
315 |
+
}
|
316 |
+
},
|
317 |
+
initValues: function(data){
|
318 |
+
if(data.result.phone){
|
319 |
+
w.Taply.savedPhone=w.Taply.format(data.result.phone);
|
320 |
+
var tbs = d.getElementsByClassName(w.Taply.btnClass), phone=w.Taply.savedPhone;
|
321 |
+
for(var i=0; i<tbs.length; i++){
|
322 |
+
var ps = tbs[i].getElementsByTagName('input');
|
323 |
+
for(var p=0;p<ps.length;p++){
|
324 |
+
if(ps[p].name == 'phone'){
|
325 |
+
ps[p].value = phone;
|
326 |
+
}
|
327 |
+
if(ps[p].name == 'save-phone'){
|
328 |
+
ps[p].checked = 1;
|
329 |
+
}
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}
|
333 |
+
},
|
334 |
+
getParamStr: function(block,er){
|
335 |
+
var p='';
|
336 |
+
switch(block.type){
|
337 |
+
case 'item':
|
338 |
+
p = "&iuid=" + block.el.attributes['data-iuid'].value;
|
339 |
+
break;
|
340 |
+
case 'cart':
|
341 |
+
p = "&cart=" + block.el.attributes['data-cart'].value;
|
342 |
+
break;
|
343 |
+
case 'auto':
|
344 |
+
// var cart = w.Taply.getCart(block);
|
345 |
+
break;
|
346 |
+
}
|
347 |
+
|
348 |
+
p += '&phone=' + block.phone.value.replace(/[\W_]/g,'')+ "&save_phone=" + (block.save_phone.checked? 1:0) + "&block_id=" + block.id;
|
349 |
+
return p; //(Taply.iuid !== undefined? "&iuid=" + Taply.iuid : "&cart=" + Taply.cart) + "&cc=" + Taply.dlg.country.value + "&phone=" + Taply.dlg.phone.value.replace(/[\W_]/g,'') + "&save_phone=" + (Taply.dlg.save_phone.checked? 1:0);
|
350 |
+
},
|
351 |
+
verify: function(block){
|
352 |
+
var pattern = new RegExp(/\(?([0-9]{3})\)?[\s]{0,1}[0-9]{3}[-]?[0-9]{4}/);
|
353 |
+
if(!pattern.test(block.phone.value)){
|
354 |
+
block.notify(w.Taply.notifies.invalidPhone);
|
355 |
+
return false;
|
356 |
+
}
|
357 |
+
return true;
|
358 |
+
},
|
359 |
+
send: function(block){
|
360 |
+
clearInterval(w.Taply.ch);
|
361 |
+
if(block.save_phone.checked){
|
362 |
+
w.Taply.savedPhone = block.phone.value;
|
363 |
+
}
|
364 |
+
if(w.Taply.verify(block)){
|
365 |
+
w.Taply.ls(w.Taply.apiurl + '/add?callback=Taply.checkResponse' + w.Taply.getParamStr(block));
|
366 |
+
}
|
367 |
+
},
|
368 |
+
cancel: function(block){
|
369 |
+
if(block.pid){
|
370 |
+
w.Taply.ls(w.Taply.apiurl + "/cancel?payment=" + block.pid);
|
371 |
+
block.initialized = false;
|
372 |
+
}
|
373 |
+
},
|
374 |
+
payLater: function(block){
|
375 |
+
if(block.pid){
|
376 |
+
w.Taply.ls(w.Taply.apiurl + "/paylater?payment=" + block.pid);
|
377 |
+
block.initialized = false;
|
378 |
+
}
|
379 |
+
},
|
380 |
+
checkResponse: function(data){
|
381 |
+
var el, n='';
|
382 |
+
if(data.result !== undefined){
|
383 |
+
el = w.Taply.modules[data.result.block_id];
|
384 |
+
}
|
385 |
+
if(data.status == "success"){
|
386 |
+
if(el === undefined){
|
387 |
+
return;
|
388 |
+
}
|
389 |
+
if (data.result.payment_result == 1){
|
390 |
+
n = w.Taply.notifies.complete;
|
391 |
+
w.Taply.ch = setInterval(w.Taply.checkPayment,1000,data.result.payment);
|
392 |
+
}else{
|
393 |
+
if(data.result.firsttime){
|
394 |
+
n = w.Taply.notifies.firstTime;
|
395 |
+
}
|
396 |
+
n = w.Taply.notifies.notInstall;
|
397 |
+
}
|
398 |
+
|
399 |
+
}else{
|
400 |
+
n=w.Taply.notifies.serverError;
|
401 |
+
w.Taply.notifyMessages[n]='';
|
402 |
+
for(var i=0;i<data.errors.length;i++){
|
403 |
+
if(data.errors[i].error_code === 'E00901'){
|
404 |
+
n = w.Taply.notifies.invalidPhone;
|
405 |
+
break;
|
406 |
+
}else{
|
407 |
+
w.Taply.notifyMessages[n]+=data.errors[i].error_message + '</br>';
|
408 |
+
}
|
409 |
+
}
|
410 |
+
}
|
411 |
+
if(el !== undefined){
|
412 |
+
el.pid = data.result.payment;
|
413 |
+
el.notify(n);
|
414 |
+
}else{
|
415 |
+
alert(w.Taply.notifyMessages[n]);
|
416 |
+
}
|
417 |
+
},
|
418 |
+
checkPayment: function(pid){
|
419 |
+
w.Taply.ls(w.Taply.apiurl + "/get-payment-status?callback=Taply.checkPaymentResponse&payment=" + pid);
|
420 |
+
},
|
421 |
+
checkPaymentResponse: function(data){
|
422 |
+
var n = 'Unknown Error, try later';
|
423 |
+
if(data.status == "success"){
|
424 |
+
if (data.result.payment_status == 0){
|
425 |
+
return;
|
426 |
+
}
|
427 |
+
if(w.TaplyDlg.current){
|
428 |
+
w.TaplyDlg.current.pid=null;
|
429 |
+
}
|
430 |
+
clearInterval(w.Taply.ch);
|
431 |
+
n = data.result.payment_status<0? data.result.payment_status : data.result.payment_status + 10;
|
432 |
+
if(data.result.redirect !== undefined){
|
433 |
+
setTimeout(function(){w.location = data.result.redirect;},3000);
|
434 |
+
}
|
435 |
+
}
|
436 |
+
if(w.TaplyDlg.current){
|
437 |
+
w.TaplyDlg.current.notify(n);
|
438 |
+
};
|
439 |
+
},
|
440 |
+
};
|
441 |
+
var css=document.createElement("style");
|
442 |
+
css.innerHTML = ".pay-module .taply-apply-pay {background: url( //www.paybytaply.com/static/img/asset/pay-by-taply-btn-dark-wide.png ) no-repeat;display: block;float: right;height: 53px;margin-bottom: 10px;font-size: 0;width: 248px;}@media only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {.pay-module .taply-apply-pay { background-image: url( //www.paybytaply.com/static/img/asset/pay-by-taply-btn-dark-2x.png );background-size: 248px 62px;}}.pay-module a {color: #6a0fa5; text-decoration: none; } .pay-module a:hover {text-decoration: underline; }.pay-module p {color: #959595; font-size: 16px; clear: both;}.pay-module h4 {color: #595959; font-size: 16px; margin-bottom: 10px; }.taply-modal button { box-shadow: none; }";
|
443 |
+
d.getElementsByTagName("head")[0].appendChild(css);
|
444 |
+
w.addEventListener('load', w.Taply.init.bind(w), false);
|
445 |
+
})(window,document);
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>taply</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>beta</stability>
|
6 |
+
<license>GNU General Public License (GPL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Add PayByTaply button in cart</summary>
|
10 |
+
<description>Taply enables e-commerce websites to accept Apple Pay. It’s easy, quick and secure for both your business and your customers. Install the taply plugin to accept Apple Pay on your website now. Register your taply account at www.paybytaply.com/signup</description>
|
11 |
+
<notes>Add taply payment method</notes>
|
12 |
+
<authors><author><name>taply</name><user>taply</user><email>admin@paybytaply.com</email></author></authors>
|
13 |
+
<date>2015-08-04</date>
|
14 |
+
<time>15:34:00</time>
|
15 |
+
<contents><target name="magelocal"><dir name="Taply"><dir name="Paybutton"><dir name="Block"><dir name="Button"><file name="Pay.php" hash="96e03a2a96daeb5e217b7071bd67dd78"/></dir></dir><dir name="Helper"><file name="Data.php" hash="c8404ec959ddf4bf9fbee31fc2314d34"/></dir><dir name="Model"><file name="Payment.php" hash="4af32846253babe72e11551003a2662c"/><file name="Viewtype.php" hash="c39cf7f525e11ab1de3f10a939caf494"/></dir><dir name="controllers"><file name="GetshippingController.php" hash="692474af6dda396e61d7a09b58cf8e3a"/><file name="SuccessController.php" hash="949118c2887944b4d5833bc8b81fb53d"/></dir><dir name="etc"><file name="config.xml" hash="f93350af38d05df42cb2ea07a708c075"/><file name="system.xml" hash="520313dbaf29da8a44325f1a2880d30a"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="taply.xml" hash="bc7a785448a0e2b2754e46fa786a5b3d"/></dir><dir name="template"><dir name="taply"><file name="button.phtml" hash="b6541c278d428eea006a782e11abe2e3"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Taply_Paybutton.xml" hash="444eaa37dfe56b3b3e738770353b2e1c"/></dir></target><target name="mage"><dir name="js"><dir name="taply"><file name="taply.1.1.js" hash="ee5176b63f1ce1a1610ddf7827650c36"/></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.4.0</min><max>5.6.999</max></php></required></dependencies>
|
18 |
+
</package>
|