DwollaPaymentModule - Version 3.0.0

Version Notes

Added Webhook support and Guest Checkout features

Download this release

Release Info

Developer Michael Schonfeld
Extension DwollaPaymentModule
Version 3.0.0
Comparing to
See all releases


Version 3.0.0

app/code/local/Dwolla/.DS_Store ADDED
Binary file
app/code/local/Dwolla/DwollaPaymentModule/.DS_Store ADDED
Binary file
app/code/local/Dwolla/DwollaPaymentModule/Block/Form.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dwolla Payment Module for Magento > 1.6
4
+ *
5
+ * @category Dwolla
6
+ * @package Dwolla_DwollaPaymentModule
7
+ * @copyright Copyright (c) 2012 Dwolla Inc. (http://www.dwolla.com)
8
+ * @autor Gordon Zheng <gordon@dwolla.com>, Michael Schonfeld <michael@dwolla.com>
9
+ * @version 3.0.0alpha
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Dwolla_DwollaPaymentModule_Block_Form extends Mage_Payment_Block_Form
14
+ {
15
+ /**
16
+ * Set template and redirect message
17
+ */
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this
22
+ ->setTemplate('dwollaPaymentModule/form.phtml')
23
+ ->setRedirectMessage(
24
+ Mage::helper('paypal')->__('You will be redirected to the Dwolla website when you place an order.')
25
+ );
26
+ }
27
+ }
app/code/local/Dwolla/DwollaPaymentModule/Helper/Data.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dwolla Payment Module for Magento > 1.6
4
+ *
5
+ * @category Dwolla
6
+ * @package Dwolla_DwollaPaymentModule
7
+ * @copyright Copyright (c) 2012 Dwolla Inc. (http://www.dwolla.com)
8
+ * @autor Gordon Zheng <gordon@dwolla.com>, Michael Schonfeld <michael@dwolla.com>
9
+ * @version 3.0.0alpha
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Dwolla_DwollaPaymentModule_Helper_Data extends Mage_Core_Helper_Abstract
14
+ {
15
+
16
+ }
app/code/local/Dwolla/DwollaPaymentModule/Model/Standard.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dwolla Payment Module for Magento > 1.6
4
+ *
5
+ * @category Dwolla
6
+ * @package Dwolla_DwollaPaymentModule
7
+ * @copyright Copyright (c) 2012 Dwolla Inc. (http://www.dwolla.com)
8
+ * @autor Gordon Zheng <gordon@dwolla.com>, Michael Schonfeld <michael@dwolla.com>
9
+ * @version 3.0.0alpha
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+
14
+ class Dwolla_DwollaPaymentModule_Model_Standard extends Mage_Payment_Model_Method_Abstract {
15
+ protected $_code = 'dwollaPaymentModule';
16
+
17
+ protected $_isInitializeNeeded = true;
18
+ protected $_canUseInternal = true;
19
+ protected $_canUseForMultishipping = true;
20
+
21
+ protected $_formBlockType = 'dwollaPaymentModule/form';
22
+
23
+ public function getOrderPlaceRedirectUrl() {
24
+ return Mage::getUrl('dwollaPaymentModule/payment/redirect', array('_secure' => true));
25
+ }
26
+ }
27
+ ?>
app/code/local/Dwolla/DwollaPaymentModule/controllers/PaymentController.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dwolla Payment Module for Magento > 1.6
4
+ *
5
+ * @category Dwolla
6
+ * @package Dwolla_DwollaPaymentModule
7
+ * @copyright Copyright (c) 2012 Dwolla Inc. (http://www.dwolla.com)
8
+ * @autor Gordon Zheng <gordon@dwolla.com>, Michael Schonfeld <michael@dwolla.com>
9
+ * @version 3.0.0alpha
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Dwolla_DwollaPaymentModule_PaymentController extends Mage_Core_Controller_Front_Action {
14
+ public function redirectAction() {
15
+ $this->loadLayout();
16
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','dwollaPaymentModule',array('template' => 'dwollaPaymentModule/redirect.phtml'));
17
+ $this->getLayout()->getBlock('content')->append($block);
18
+ $this->renderLayout();
19
+ }
20
+
21
+ public function webhookAction() {
22
+ /*
23
+ Receives transactions status change notifications and updates order statuses
24
+ */
25
+
26
+ // retrieve user configuration:
27
+ $apiSecret = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaApiSecret');
28
+
29
+ // parse raw json-encoded POST data
30
+ $json_data = $this->getRequest()->getRawBody();
31
+ $data = json_decode($json_data);
32
+
33
+ $type = $data->Type;
34
+ $subtype = $data->Subtype;
35
+ $id = $data->Id;
36
+ $created = $data->Created;
37
+ $triggered = $data->Triggered;
38
+ $value = $data->Value;
39
+
40
+ // verify signature:
41
+ $signature = $this->getRequest()->getHeader('X-Dwolla-Signature');
42
+
43
+ $hash = hash_hmac('sha1', $json_data, $apiSecret);
44
+ $validated = ($hash == $signature);
45
+
46
+ // retrieve order based on transaction ID:
47
+ $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('dwolla_transaction_id', $id);
48
+
49
+ // If no orders were found, wait 5 seconds, then try again
50
+ // This might happen when users pay from their Dwolla balance
51
+ // and the Webhook hits before the redirect registers
52
+ if(!$orders || sizeof($orders) < 1) {
53
+ sleep(5);
54
+ $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('dwolla_transaction_id', $id);
55
+ }
56
+
57
+ // update order state and status based on notification of new status:
58
+ $status_to_order_state = array(
59
+ "completed" => Mage_Sales_Model_Order::STATE_PROCESSING,
60
+ "pending" => Mage_Sales_Model_Order::STATE_PROCESSING,
61
+ "failed" => Mage_Sales_Model_Order::STATE_CANCELED,
62
+ "cancelled" => Mage_Sales_Model_Order::STATE_CANCELED,
63
+ "reclaimed" => Mage_Sales_Model_Order::STATE_CANCELED,
64
+ "processed" => "payment_complete"
65
+ );
66
+
67
+ foreach($orders as $order) {
68
+ $message = '';
69
+
70
+ if($validated) {
71
+ $message = "Current Dwolla transaction status: {$value}, as of {$triggered}. Dwolla's signature was successfully verified.";
72
+ } else {
73
+ $value = 'failed';
74
+ $message = "Dwolla's signature failed to verify. Terminating order. Contact support@dwolla.com with the following information: Proposed signature: {$signature} ... Expected Signature: {$hash} ... Body: {$json_data}";
75
+ }
76
+
77
+ $order->setState($status_to_order_state[$value], true, $message);
78
+ $order->setStatus($status_to_order_state[$value]);
79
+ $order->save();
80
+
81
+ echo "Magento order ID #{$order['increment_id']} / Dwolla Transaction ID #{$id} is now set to {$status_to_order_state[$value]}.";
82
+ }
83
+
84
+ // always respond to Dwolla with 200/OK, else Dwolla will try sending a second time:
85
+ $this->getResponse()->setHttpResponseCode(200);
86
+ }
87
+
88
+ public function responseAction() {
89
+ // Get User Configuration
90
+ $dwollaId = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaId');
91
+ $apiKey = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaApiKey');
92
+ $apiSecret = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaApiSecret');
93
+
94
+ // Grab Dwolla's Response
95
+ $orderId = $this->getRequest()->orderId;
96
+ $checkoutId = $this->getRequest()->checkoutId;
97
+ $transactionId = $this->getRequest()->transaction;
98
+ $amount = $this->getRequest()->amount;
99
+ $signature = $this->getRequest()->signature;
100
+
101
+ // Check if the user cancelled, or
102
+ // if there was any other error
103
+ $isError = $this->getRequest()->error;
104
+ $errorDescription = $this->getRequest()->error_description;
105
+
106
+ if($isError) {
107
+ return $this->cancelAction($orderId, $errorDescription);
108
+ }
109
+
110
+ // Validate Dwolla's Signature
111
+ $string = "{$checkoutId}&{$amount}";
112
+ $hash = hash_hmac('sha1', $string, $apiSecret);
113
+ $validated = ($hash == $signature);
114
+
115
+ if($validated) {
116
+ $order = Mage::getModel('sales/order');
117
+ $order->loadByIncrementId($orderId);
118
+ $order->setDwollaTransactionId($transactionId);
119
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, "Dwolla Gateway informed us: the payment's Transaction ID is {$transactionId} / Checkout ID {$checkoutId}");
120
+
121
+ $order->sendNewOrderEmail();
122
+ $order->setEmailSent(true);
123
+ $order->save();
124
+
125
+ Mage::getSingleton('checkout/session')->unsQuoteId();
126
+
127
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
128
+ }
129
+ else {
130
+ $this->cancelAction(FALSE, 'Dwolla signature did not validate');
131
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
132
+ }
133
+ }
134
+
135
+ public function cancelAction($orderId = FALSE, $errorDescription = "Unknown reason") {
136
+ if(!$orderId) {
137
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
138
+ }
139
+
140
+ if ($orderId) {
141
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
142
+ if($order->getId()) {
143
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, "Gateway has declined the payment: {$errorDescription}.")->save();
144
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
145
+ }
146
+ }
147
+ }
148
+ }
app/code/local/Dwolla/DwollaPaymentModule/etc/config.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dwolla_DwollaPaymentModule>
5
+ <version>3.0.0</version>
6
+ </Dwolla_DwollaPaymentModule>
7
+ </modules>
8
+ <global>
9
+ <resources>
10
+ <DwollaPaymentModule_setup>
11
+ <setup>
12
+ <module>Dwolla_DwollaPaymentModule</module>
13
+ <class>Mage_Core_Model_Resource_Setup</class>
14
+ </setup>
15
+ <connection>
16
+ <use>core_setup</use>
17
+ </connection>
18
+ </DwollaPaymentModule_setup>
19
+ </resources>
20
+ <models>
21
+ <dwollaPaymentModule>
22
+ <class>Dwolla_DwollaPaymentModule_Model</class>
23
+ </dwollaPaymentModule>
24
+ </models>
25
+ <helpers>
26
+ <dwollaPaymentModule>
27
+ <class>Dwolla_DwollaPaymentModule_Helper</class>
28
+ </dwollaPaymentModule>
29
+ </helpers>
30
+ <blocks>
31
+ <dwollaPaymentModule>
32
+ <class>Dwolla_DwollaPaymentModule_Block</class>
33
+ </dwollaPaymentModule>
34
+ </blocks>
35
+ </global>
36
+ <default>
37
+ <payment>
38
+ <dwollaPaymentModule>
39
+ <model>dwollaPaymentModule/standard</model>
40
+ <active>1</active>
41
+ <dwollaTestMode>0</dwollaTestMode>
42
+ <order_status>pending</order_status>
43
+ <title>Dwolla</title>
44
+ <payment_action>sale</payment_action>
45
+ <dwollaGuestCheckout>1</dwollaGuestCheckout>
46
+ <showDwollaLogo>1</showDwollaLogo>
47
+ <allowspecific>0</allowspecific>
48
+ <sort_order>1</sort_order>
49
+ </dwollaPaymentModule>
50
+ </payment>
51
+ </default>
52
+ <frontend>
53
+ <routers>
54
+ <dwollaPaymentModule>
55
+ <use>standard</use>
56
+ <args>
57
+ <module>Dwolla_DwollaPaymentModule</module>
58
+ <frontName>dwollaPaymentModule</frontName>
59
+ </args>
60
+ </dwollaPaymentModule>
61
+ </routers>
62
+ </frontend>
63
+ </config>
app/code/local/Dwolla/DwollaPaymentModule/etc/system.xml ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <dwollaPaymentModule translate="label comment" module="paygate">
7
+ <label>Dwolla</label>
8
+ <comment><![CDATA[
9
+ <h3>Setup</h3><ul>
10
+ <li><a href="https://www.dwolla.com/applications/create" target="_blank">Click here to create a Dwolla Application and generate your Dwolla API credentials</a></li>
11
+
12
+ <li>You must enable the Webhook feature for your Dwolla Application and set the 'All URL' to: <br> http://[YOUR DOMAIN HERE]/index.php/dwollaPaymentModule/payment/webhook
13
+ </li>
14
+ </ul>]]></comment>
15
+ <sort_order>670</sort_order>
16
+ <frontend_type>text</frontend_type>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <active translate="label">
22
+ <label>Enabled</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>10</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
+ </active>
30
+ <title translate="label">
31
+ <label>Payment Method Name</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>20</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </title>
38
+ <order_status translate="label">
39
+ <label>New Order Status</label>
40
+ <frontend_type>select</frontend_type>
41
+ <source_model>adminhtml/system_config_source_order_status</source_model>
42
+ <sort_order>50</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
+ </order_status>
47
+ <allowspecific translate="label">
48
+ <label>Payment Applicable From</label>
49
+ <frontend_type>select</frontend_type>
50
+ <sort_order>61</sort_order>
51
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>0</show_in_store>
55
+ </allowspecific>
56
+ <specificcountry translate="label">
57
+ <label>Countries Payment Applicable From</label>
58
+ <frontend_type>multiselect</frontend_type>
59
+ <sort_order>70</sort_order>
60
+ <source_model>adminhtml/system_config_source_country</source_model>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>0</show_in_store>
64
+ <depends>
65
+ <allowspecific>1</allowspecific>
66
+ </depends>
67
+ </specificcountry>
68
+
69
+ <dwollaId translate="label">
70
+ <label>Send Money to Dwolla ID</label>
71
+ <frontend_type>text</frontend_type>
72
+ <sort_order>80</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ </dwollaId>
77
+ <dwollaApiKey translate="label">
78
+ <label>API Key</label>
79
+ <frontend_type>text</frontend_type>
80
+ <sort_order>90</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </dwollaApiKey>
85
+ <dwollaApiSecret translate="label">
86
+ <label>API Secret</label>
87
+ <frontend_type>text</frontend_type>
88
+ <sort_order>100</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </dwollaApiSecret>
93
+ <dwollaTestMode translate="label">
94
+ <label>Run In Test Mode?</label>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_yesno</source_model>
97
+ <sort_order>110</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>1</show_in_store>
101
+ </dwollaTestMode>
102
+
103
+ <dwollaGuestCheckout translate="label">
104
+ <label>Allow Guest Checkout?</label>
105
+ <frontend_type>select</frontend_type>
106
+ <source_model>adminhtml/system_config_source_yesno</source_model>
107
+ <sort_order>120</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ </dwollaGuestCheckout>
112
+
113
+ <showDwollaLogo translate="label">
114
+ <label>Show Dwolla Logo At Checkout?</label>
115
+ <frontend_type>select</frontend_type>
116
+ <source_model>adminhtml/system_config_source_yesno</source_model>
117
+ <sort_order>120</sort_order>
118
+ <show_in_default>1</show_in_default>
119
+ <show_in_website>1</show_in_website>
120
+ <show_in_store>1</show_in_store>
121
+ </showDwollaLogo>
122
+
123
+ <sort_order translate="label">
124
+ <label>Sort Order</label>
125
+ <frontend_type>text</frontend_type>
126
+ </sort_order>
127
+ <sort_order>100</sort_order>
128
+ <show_in_default>1</show_in_default>
129
+ <show_in_website>1</show_in_website>
130
+ <show_in_store>0</show_in_store>
131
+ </fields>
132
+ </dwollaPaymentModule>
133
+ </groups>
134
+ </payment>
135
+ </sections>
136
+ </config>
app/code/local/Dwolla/DwollaPaymentModule/sql/.DS_Store ADDED
Binary file
app/code/local/Dwolla/DwollaPaymentModule/sql/DwollaPaymentModule_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $installer = new Mage_Sales_Model_Mysql4_Setup;
2
+ $installer->startSetup();
3
+ $attribute = array(
4
+ 'type' => 'text',
5
+ 'backend_type' => 'text',
6
+ 'frontend_input' => 'text',
7
+ 'is_user_defined' => true,
8
+ 'label' => 'Transaction Id',
9
+ 'visible' => true,
10
+ 'required' => false,
11
+ 'user_defined' => false,
12
+ 'searchable' => false,
13
+ 'filterable' => false,
14
+ 'comparable' => false,
15
+ 'default' => ''
16
+ );
17
+ $installer->addAttribute('order', 'transaction_id', $attribute);
18
+ $installer->endSetup();
app/code/local/Dwolla/DwollaPaymentModule/sql/DwollaPaymentModule_setup/mysql4-install-3.0.0.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = new Mage_Sales_Model_Mysql4_Setup;
3
+
4
+ $installer->startSetup();
5
+
6
+ $attribute = array(
7
+ 'type' => 'text',
8
+ 'backend_type' => 'text',
9
+ 'frontend_input' => 'text',
10
+ 'is_user_defined' => true,
11
+ 'label' => 'Dwolla Transaction ID',
12
+ 'visible' => true,
13
+ 'required' => false,
14
+ 'user_defined' => false,
15
+ 'searchable' => true,
16
+ 'filterable' => true,
17
+ 'comparable' => false,
18
+ 'default' => ''
19
+ );
20
+ $installer->addAttribute('order', 'dwolla_transaction_id', $attribute);
21
+
22
+ $status = Mage::getModel('sales/order_status');
23
+
24
+ $status->setStatus('payment_complete')->setLabel('Payment Complete')
25
+ ->assignState('payment_complete') //for example, use any available existing state
26
+ ->save();
27
+
28
+ $installer->endSetup();
app/design/frontend/base/default/template/dwollaPaymentModule/form.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <ul class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
2
+ <?php
3
+ $showDwollaLogo = Mage::getStoreConfig('payment/dwollaPaymentModule/showDwollaLogo');
4
+ if ($showDwollaLogo) {
5
+ echo "<img src=" . $this->getSkinUrl('../../dwollaPaymentModule/default/dwolla-sm-no-bg.png') . " />";
6
+ }?>
7
+ <li class="form-alt"><?php echo $this->getRedirectMessage() ?></li>
8
+ </ul>
app/design/frontend/base/default/template/dwollaPaymentModule/redirect.phtml ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dwolla Payment Module for Magento > 1.6
4
+ *
5
+ * @category Dwolla
6
+ * @package Dwolla_DwollaPaymentModule
7
+ * @copyright Copyright (c) 2012 Dwolla Inc. (http://www.dwolla.com)
8
+ * @autor Gordon Zheng <gordon@dwolla.com>, Michael Schonfeld <michael@dwolla.com>
9
+ * @version 3.0.0alpha
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ // Get User Configuration
14
+ $dwollaId = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaId');
15
+ $apiKey = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaApiKey');
16
+ $apiSecret = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaApiSecret');
17
+ $testMode = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaTestMode');
18
+ $allowGuestCheckout = Mage::getStoreConfig('payment/dwollaPaymentModule/dwollaGuestCheckout');
19
+
20
+ // Make sure we have all the information we need
21
+ // before we continue
22
+ if(!$dwollaId || !$apiKey || !$apiSecret) {
23
+ echo "The Dwolla Gateway seems to be misconfigured. Please use another payment method.";
24
+ break;
25
+ }
26
+
27
+ // Parsing Dwolla IDs
28
+ function parseDwollaId($id) {
29
+ $id = ereg_replace("[^0-9]", "", $id);
30
+ $id = substr($id, 0, 3) . '-' . substr($id, 3, 3) . '-' . substr($id, 6, 4);
31
+
32
+ return $id;
33
+ }
34
+
35
+ // Grab the user's order
36
+ $magOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
37
+ $order = Mage::getModel('sales/order')->loadByIncrementId($magOrderId);
38
+
39
+ $items = array();
40
+ foreach($order->getItemsCollection() as $item) {
41
+ if($item->getQtyToShip() > 0) {
42
+ $items[] = array(
43
+ 'Description' => $item->getSku() . ': ' . ($item->getDescription() ? $item->getDescription() : 'N/A'),
44
+ 'Name' => $item->getName(),
45
+ 'Price' => $item->getPrice(),
46
+ 'Quantity' => $item->getQtyToShip()
47
+ );
48
+ }
49
+ }
50
+
51
+ // Generate a checkout ID from Dwolla
52
+ $dwollaJson = array(
53
+ 'key' => $apiKey,
54
+ 'secret' => $apiSecret,
55
+ 'redirect' => Mage::getUrl('dwollaPaymentModule/payment/response', array('_secure' => true)),
56
+ 'orderId' => $magOrderId,
57
+ 'test' => $testMode ? 'true' : 'false',
58
+ 'allowfundingsources' => $allowGuestCheckout ? 'true' : 'false',
59
+ 'purchaseOrder' => array(
60
+ 'destinationId' => parseDwollaId($dwollaId),
61
+ 'discount' => $order->getDiscountAmount(),
62
+ 'shipping' => $order->getShippingAmount(),
63
+ 'tax' => $order->getTaxAmount(),
64
+ 'total' => $order->getGrandTotal(),
65
+ 'orderItems' => $items
66
+ )
67
+ );
68
+
69
+ $ch = curl_init("https://www.dwolla.com/payment/request");
70
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
71
+ curl_setopt($ch, CURLOPT_POST, 1);
72
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dwollaJson));
73
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
74
+ $output = json_decode(curl_exec($ch), TRUE);
75
+ curl_close($ch);
76
+
77
+ // Make sure we got a checkout ID
78
+ if(!$output['CheckoutId']) {
79
+ $debug = print_r($dwollaJson, TRUE);
80
+ $message = "Something went wrong while redirecting the customer to Dwolla's gateway. Here's what Dwolla said: {$output['Message']} ... Contact support@dwolla.com with the following information: Debug information: {$debug}";
81
+ $order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, $message);
82
+ $order->save();
83
+
84
+ echo "Something went wrong. Dwolla said: {$output['Message']}. Contact the store owner for more information.";
85
+ break;
86
+ }
87
+ $dwollaUrl = "https://www.dwolla.com/payment/checkout/{$output['CheckoutId']}";
88
+
89
+ // Redirect to Dwolla's off-site payment gateway
90
+ header("Location: {$dwollaUrl}");
91
+ ?>
92
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
93
+ <html>
94
+ <head>
95
+ <title>Redirecting to Dwolla</title>
96
+ <meta http-equiv="REFRESH" content="0;url=<?php echo $dwollaUrl; ?>"></HEAD>
97
+ <BODY>
98
+ Redirecting you to the Dwolla Off-Site Gateway now. Click <a href="<?php echo $dwollaUrl; ?>">here</a> if you are not automatically redirected.
99
+ </BODY>
100
+ </HTML>
app/etc/modules/Dwolla_DwollaPaymentModule.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Dwolla_DwollaPaymentModule>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ <depends>
7
+ <Mage_Payment />
8
+ </depends>
9
+ </Dwolla_DwollaPaymentModule>
10
+ </modules>
11
+ </config>
package.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DwollaPaymentModule</name>
4
+ <version>3.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>MIT License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The Dwolla payment extension for Magento - quick, secure integration with the Dwolla money-moving engine.</summary>
10
+ <description>The Dwolla payment module extension for Magento allows your store to quickly, securely integrate with the Dwolla money-mover engine.&#xD;
11
+ &#xD;
12
+ Payments are captured in real time as part of the standard checkout process.&#xD;
13
+ &#xD;
14
+ Dwolla is a platform for moving funds electronically, and securely. Transactions are completely free for amounts of $10 and under, and cost $0.25 flat-fee for any amount larger than $10.&#xD;
15
+ &#xD;
16
+ A customer must have a Dwolla account to pay with Dwolla. Dwolla accounts are free for consumers and merchants.&#xD;
17
+ &#xD;
18
+ Dwolla is available for U.S. residents and bank accounts only.&#xD;
19
+ &#xD;
20
+ https://www.dwolla.com</description>
21
+ <notes>Added Webhook support and Guest Checkout features</notes>
22
+ <authors><author><name>Michael Schonfeld</name><user>dwolla</user><email>api@dwolla.com</email></author><author><name>Gordon Zheng</name><user>gordon-dwolla</user><email>gordon@dwolla.com</email></author></authors>
23
+ <date>2013-03-26</date>
24
+ <time>04:32:44</time>
25
+ <contents><target name="magelocal"><dir name="Dwolla"><dir name="DwollaPaymentModule"><dir name="Block"><file name="Form.php" hash="c70174d6c5e698651cbf6a751167aba8"/></dir><dir name="Helper"><file name="Data.php" hash="c722dde6902086b4dd542ff927d1ad06"/></dir><dir name="Model"><file name="Standard.php" hash="539da0180dfc999070f374bd6a9373eb"/></dir><dir name="controllers"><file name="PaymentController.php" hash="034b11680796f9662684591eae63898d"/></dir><dir name="etc"><file name="config.xml" hash="f5b7e91bc93e2e0d53d4b1393bf66a2a"/><file name="system.xml" hash="57b24b47592310af9df586bb4d1d205f"/></dir><dir name="sql"><dir name="DwollaPaymentModule_setup"><file name="mysql4-install-0.1.0.php" hash="ccd751cd88d43cf84609b8500b7800cb"/><file name="mysql4-install-3.0.0.php" hash="ba589219d8bfe3c974ddb238df122fc7"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><file name=".DS_Store" hash="2485f7770e2f67af8fcb8f3cc90cbb16"/></dir><file name=".DS_Store" hash="a10d50f6fdca432768429929c848c60e"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="dwollaPaymentModule"><file name="form.phtml" hash="9d3aef1a028d0da1d151c3f11e65bff1"/><file name="redirect.phtml" hash="aee68c2511ab52d6082d01c9bca00b95"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Dwolla_DwollaPaymentModule.xml" hash="61871f4d96d1ff4bad1ab6e8f4f97ac5"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="dwollaPaymentModule"><dir name="default"><file name="dwolla-sm-no-bg.png" hash="a53703a5bd77615ad0c18e2e71d72311"/></dir></dir></dir></target></contents>
26
+ <compatible/>
27
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
28
+ </package>
skin/frontend/dwollaPaymentModule/default/dwolla-sm-no-bg.png ADDED
Binary file