Tritac_Capayable - Version 1.0.0

Version Notes

Version 1.0.0

Download this release

Release Info

Developer Capayable
Extension Tritac_Capayable
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (28) hide show
  1. app/code/community/Tritac/Capayable/Block/Form.php +54 -0
  2. app/code/community/Tritac/Capayable/Block/Info.php +58 -0
  3. app/code/community/Tritac/Capayable/Helper/Data.php +34 -0
  4. app/code/community/Tritac/Capayable/Model/Customer.php +98 -0
  5. app/code/community/Tritac/Capayable/Model/Observer.php +124 -0
  6. app/code/community/Tritac/Capayable/Model/Payment.php +240 -0
  7. app/code/community/Tritac/Capayable/Model/Resource/Customer.php +69 -0
  8. app/code/community/Tritac/Capayable/Model/Resource/Customer/Collection.php +14 -0
  9. app/code/community/Tritac/Capayable/Model/Resource/Setup.php +13 -0
  10. app/code/community/Tritac/Capayable/etc/config.xml +129 -0
  11. app/code/community/Tritac/Capayable/etc/system.xml +78 -0
  12. app/code/community/Tritac/Capayable/sql/capayable_setup/install-1.0.0.php +73 -0
  13. app/design/frontend/base/default/template/capayable/form.phtml +140 -0
  14. app/design/frontend/base/default/template/capayable/info.phtml +2 -0
  15. app/etc/modules/Tritac_Capayable.xml +17 -0
  16. app/locale/nl_NL/Tritac_Capayable.csv +17 -0
  17. lib/Tritac/CapayableApiClient/AddTrustExternalCARoot.crt +25 -0
  18. lib/Tritac/CapayableApiClient/Client.php +186 -0
  19. lib/Tritac/CapayableApiClient/Enums/Environment.php +8 -0
  20. lib/Tritac/CapayableApiClient/Enums/Gender.php +8 -0
  21. lib/Tritac/CapayableApiClient/Enums/HttpMethod.php +9 -0
  22. lib/Tritac/CapayableApiClient/Models/BaseModel.php +32 -0
  23. lib/Tritac/CapayableApiClient/Models/CreditCheckRequest.php +228 -0
  24. lib/Tritac/CapayableApiClient/Models/CreditCheckResponse.php +18 -0
  25. lib/Tritac/CapayableApiClient/Models/Invoice.php +68 -0
  26. lib/Tritac/CapayableApiClient/fiddler.crt +21 -0
  27. lib/Tritac/CapayableApiClient/loader.php +14 -0
  28. package.xml +24 -0
app/code/community/Tritac/Capayable/Block/Form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Tritac_Capayable_Block_Form extends Mage_Payment_Block_Form
10
+ {
11
+ /**
12
+ * @var Mage_Sales_Model_Quote
13
+ */
14
+ protected $_quote;
15
+
16
+ /**
17
+ * @var Tritac_Capayable_Model_Customer
18
+ */
19
+ protected $_customer;
20
+
21
+ protected function _construct()
22
+ {
23
+ parent::_construct();
24
+ $this->setTemplate('capayable/form.phtml');
25
+ }
26
+
27
+ /**
28
+ * Get quote
29
+ *
30
+ * @return Mage_Sales_Model_Quote
31
+ */
32
+ public function getQuote() {
33
+ if(!$this->_quote) {
34
+ $this->_quote = $this->getMethod()->getInfoInstance()->getQuote();
35
+ }
36
+
37
+ return $this->_quote;
38
+ }
39
+
40
+ /**
41
+ * Get capayable customer
42
+ *
43
+ * @return Tritac_Capayable_Model_Customer
44
+ */
45
+ public function getCustomer() {
46
+ if(!$this->_customer) {
47
+ $email = $this->getQuote()->getCustomerEmail();
48
+ // If customer doesn't exists then return empty model
49
+ $this->_customer = Mage::getModel('capayable/customer')->loadByEmail($email);
50
+ }
51
+
52
+ return $this->_customer;
53
+ }
54
+ }
app/code/community/Tritac/Capayable/Block/Info.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Tritac_Capayable_Block_Info extends Mage_Payment_Block_Info
10
+ {
11
+
12
+ /**
13
+ * @var Mage_Sales_Model_Quote
14
+ */
15
+ protected $_quote;
16
+
17
+ /**
18
+ * @var Tritac_Capayable_Model_Customer
19
+ */
20
+ protected $_customer;
21
+
22
+ /**
23
+ * Set block template
24
+ */
25
+ protected function _construct()
26
+ {
27
+ parent::_construct();
28
+ $this->setTemplate('capayable/info.phtml');
29
+ }
30
+
31
+ /**
32
+ * Get quote
33
+ *
34
+ * @return Mage_Sales_Model_Quote
35
+ */
36
+ public function getQuote() {
37
+ if(!$this->_quote) {
38
+ $this->_quote = $this->getMethod()->getInfoInstance()->getQuote();
39
+ }
40
+
41
+ return $this->_quote;
42
+ }
43
+
44
+ /**
45
+ * Get capayable customer
46
+ *
47
+ * @return Tritac_Capayable_Model_Customer
48
+ */
49
+ public function getCustomer() {
50
+ if(!$this->_customer) {
51
+ $email = $this->getQuote()->getCustomerEmail();
52
+ // If customer doesn't exists then return empty model
53
+ $this->_customer = Mage::getModel('capayable/customer')->loadByEmail($email);
54
+ }
55
+
56
+ return $this->_customer;
57
+ }
58
+ }
app/code/community/Tritac/Capayable/Helper/Data.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Tritac_Capayable_Helper_Data extends Mage_Core_Helper_Abstract {
10
+
11
+ /**
12
+ * Get current extension environment
13
+ *
14
+ * @return int
15
+ */
16
+ public function getMode() {
17
+ $configMode = Mage::getStoreConfig('payment/capayable/test');
18
+ if($configMode) {
19
+ return Tritac_CapayableApiClient_Enums_Environment::TEST;
20
+ } else {
21
+ return Tritac_CapayableApiClient_Enums_Environment::PROD;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Convert price to cents.
27
+ *
28
+ * @param $amount
29
+ * @return int
30
+ */
31
+ public function convertToCents($amount) {
32
+ return (int) ($amount * 100);
33
+ }
34
+ }
app/code/community/Tritac/Capayable/Model/Customer.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Capayable customer model
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ class Tritac_Capayable_Model_Customer extends Mage_Core_Model_Abstract {
12
+
13
+ public function _construct() {
14
+ $this->_init('capayable/customer');
15
+ }
16
+
17
+ /**
18
+ * Load capayable customer by email
19
+ *
20
+ * @param string $email
21
+ * @return Tritac_Capayable_Model_Customer
22
+ */
23
+ public function loadByEmail($email)
24
+ {
25
+ $this->_getResource()->loadByEmail($this, $email);
26
+ return $this;
27
+ }
28
+
29
+ /**
30
+ * Load capayable customer by customer id
31
+ *
32
+ * @param string $customerId
33
+ * @return Tritac_Capayable_Model_Customer
34
+ */
35
+ public function loadByCustomerId($customerId)
36
+ {
37
+ $this->_getResource()->loadByCustomerId($this, $customerId);
38
+ return $this;
39
+ }
40
+
41
+ /**
42
+ * Validate capayable customer required fields
43
+ *
44
+ * @return array|bool
45
+ */
46
+ public function validate() {
47
+
48
+ $errors = array();
49
+ if (!Zend_Validate::is( trim($this->getCustomerLastname()) , 'NotEmpty')) {
50
+ $errors[] = Mage::helper('capayable')->__('The first name cannot be empty.');
51
+ }
52
+
53
+ if (!Zend_Validate::is( trim($this->getCustomerMiddlename()) , 'NotEmpty')) {
54
+ $errors[] = Mage::helper('capayable')->__('The initials cannot be empty.');
55
+ }
56
+
57
+ if (!Zend_Validate::is($this->getCustomerEmail(), 'EmailAddress')) {
58
+ $errors[] = Mage::helper('capayable')->__('Invalid email address "%s".', $this->getEmail());
59
+ }
60
+
61
+ if (!Zend_Validate::is($this->getCustomerGender(), 'NotEmpty')) {
62
+ $errors[] = Mage::helper('capayable')->__('Gender is required.');
63
+ }
64
+
65
+ if (!Zend_Validate::is($this->getCustomerDob(), 'Date', array('format' => 'yyyy-MM-dd hh:ii:ss'))) {
66
+ $errors[] = Mage::helper('capayable')->__('The Date of Birth is requiredd.');
67
+ }
68
+
69
+ if (!Zend_Validate::is($this->getStreet(), 'NotEmpty')) {
70
+ $errors[] = Mage::helper('capayable')->__('The street is required.');
71
+ }
72
+
73
+ if (!Zend_Validate::is($this->getHouseNumber(), 'Alnum')) {
74
+ $errors[] = Mage::helper('capayable')->__('House number must be a numeric.');
75
+ }
76
+
77
+ if (!Zend_Validate::is($this->getPostcode(), 'NotEmpty')) {
78
+ $errors[] = Mage::helper('capayable')->__('The zip/postal is required.');
79
+ }
80
+
81
+ if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) {
82
+ $errors[] = Mage::helper('capayable')->__('The city is required.');
83
+ }
84
+
85
+ if (!Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
86
+ $errors[] = Mage::helper('capayable')->__('The country is required.');
87
+ }
88
+
89
+ if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
90
+ $errors[] = Mage::helper('capayable')->__('the telephone number is required.');
91
+ }
92
+
93
+ if (empty($errors)) {
94
+ return true;
95
+ }
96
+ return $errors;
97
+ }
98
+ }
app/code/community/Tritac/Capayable/Model/Observer.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Tritac_Capayable_Model_Observer
10
+ {
11
+ public function processInvoice(Varien_Event_Observer $observer)
12
+ {
13
+ $event = $observer->getEvent();
14
+ /** @var $_shipment Mage_Sales_Model_Order_Shipment */
15
+ $_shipment = $event->getShipment();
16
+ /** @var $_order Mage_Sales_Model_Order */
17
+ $_order = $_shipment->getOrder();
18
+ /** @var $payment */
19
+ $payment = $_order->getPayment();
20
+ /** @var $paymentInstance */
21
+ $paymentInstance = $payment->getMethodInstance();
22
+
23
+ /**
24
+ * Check if user choose Capayable payment method
25
+ */
26
+ if($paymentInstance->getCode() == 'capayable') {
27
+
28
+ $_order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_INVOICE, true);
29
+ $customerEmail = $_order->getCustomerEmail();
30
+ $_capayableCustomer = Mage::getModel('capayable/customer')->loadByEmail($customerEmail);
31
+
32
+ /**
33
+ * Customer credit check
34
+ */
35
+ $amount = Mage::helper('capayable')->convertToCents($_order->getGrandTotal());
36
+ $apiResult = $paymentInstance->checkCredit($_capayableCustomer, $amount, true);
37
+
38
+ if(!$apiResult->getIsAccepted() || !$apiResult->getTransactionNumber()) {
39
+ return false;
40
+ }
41
+
42
+ /**
43
+ * Prepare shipped items that need to be added to invoice
44
+ */
45
+ foreach ($_shipment->getItemsCollection() as $item) {
46
+ $qtys[$item->getOrderItemId()] = $item->getQty();
47
+ }
48
+
49
+ try {
50
+ // Initialize new magento invoice
51
+ $invoice = Mage::getModel('sales/service_order', $_order)->prepareInvoice($qtys);
52
+ // Throw exception if invoice don't have any items
53
+ if(!$invoice->getTotalQty()) {
54
+ Mage::throwException(Mage::helper('core')->__('Cannot create an empty invoice.'));
55
+ }
56
+ // Set magento transaction id which returned from capayable
57
+ $payment->setTransactionId($apiResult->getTransactionNumber());
58
+ // Allow payment capture and register new magento transaction
59
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
60
+ // Register invoice and apply it to order, order items etc.
61
+ $invoice->register();
62
+ $invoice->setEmailSent(true);
63
+ $invoice->getOrder()->setIsInProcess(true);
64
+
65
+ $transaction = Mage::getModel('core/resource_transaction')
66
+ ->addObject($invoice)
67
+ ->addObject($invoice->getOrder());
68
+ // Commit changes or rollback if error has occurred
69
+ $transaction->save();
70
+
71
+ /**
72
+ * Register invoice with Capayable
73
+ */
74
+ $isApiInvoiceAccepted = $paymentInstance->processApiInvoice($invoice);
75
+
76
+ if($isApiInvoiceAccepted) {
77
+
78
+ // Send email notification about registered invoice
79
+ $invoice->sendEmail(true);
80
+ } else {
81
+ $this->_getSession()->addError(Mage::helper('capayable')->__('Invoice denied by capayable.'));
82
+ }
83
+
84
+ } catch (Mage_Core_Exception $e) {
85
+ $this->_getSession()->addError($e->getMessage());
86
+ } catch (Exception $e) {
87
+ $this->_getSession()->addError($e->getMessage());
88
+ Mage::logException($e);
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * If order paid with capayable payment method then disable creating order invoice.
95
+ * Invoice will be created automatically only after creating shipment.
96
+ *
97
+ * @param Varien_Event_Observer $observer
98
+ */
99
+ public function disableOrderInvoice(Varien_Event_Observer $observer) {
100
+ $event = $observer->getEvent();
101
+ $_order = $event->getOrder();
102
+ $_payment = $_order->getPayment();
103
+
104
+ /**
105
+ * Set order invoice flag to false
106
+ *
107
+ * @see Mage_Sales_Model_Order::canInvoice();
108
+ * @see Mage_Adminhtml_Block_Sales_Order_View::__construct(); Do not add invoice button to adminhtml view.
109
+ */
110
+ if($_payment->getMethod() == Mage::getModel('capayable/payment')->getCode()) {
111
+ $_order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_INVOICE, false);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Retrieve adminhtml session model object
117
+ *
118
+ * @return Mage_Adminhtml_Model_Session
119
+ */
120
+ protected function _getSession()
121
+ {
122
+ return Mage::getSingleton('adminhtml/session');
123
+ }
124
+ }
app/code/community/Tritac/Capayable/Model/Payment.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Capayable payment method model
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ class Tritac_Capayable_Model_Payment extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+ /**
14
+ * Unique internal payment method identifier
15
+ */
16
+ protected $_code = 'capayable';
17
+ protected $_paymentMethod = 'Capayable';
18
+ protected $_formBlockType = 'capayable/form';
19
+ protected $_infoBlockType = 'capayable/info';
20
+
21
+ /**
22
+ * Availability options
23
+ */
24
+ protected $_isGateway = true;
25
+ protected $_canOrder = true;
26
+ protected $_canAuthorize = true;
27
+ protected $_canCapture = true;
28
+ protected $_canCapturePartial = false;
29
+ protected $_canRefundInvoicePartial = false;
30
+ protected $_canVoid = false;
31
+
32
+ /**
33
+ * Capayable API client
34
+ */
35
+ protected $_client = null;
36
+
37
+ /**
38
+ * Extension helper
39
+ */
40
+ protected $_helper = null;
41
+
42
+ public function __construct()
43
+ {
44
+ $this->_helper = Mage::helper('capayable');
45
+
46
+ $public_key = $this->getConfigData('public_key');
47
+ $secret_key = $this->getConfigData('secret_key');
48
+
49
+ /**
50
+ * Initialize new api client
51
+ * @var Tritac_CapayableApiClient_Client _client
52
+ */
53
+ $this->_client = new Tritac_CapayableApiClient_Client($public_key, $secret_key, $this->_helper->getMode());
54
+
55
+ parent::__construct();
56
+ }
57
+
58
+ /**
59
+ * Get capayable helper
60
+ *
61
+ * @return Mage_Core_Helper_Abstract|Mage_Payment_Helper_Data|null
62
+ */
63
+ public function getHelper() {
64
+ return $this->_helper;
65
+ }
66
+
67
+ /**
68
+ * Check customer credit via capayable
69
+ *
70
+ * @param Varien_Object $payment
71
+ * @param float $amount
72
+ * @return $this|Mage_Payment_Model_Abstract
73
+ * @throws Mage_Payment_Model_Info_Exception
74
+ */
75
+ public function authorize(Varien_Object $payment, $amount) {
76
+
77
+ if ($amount <= 0) {
78
+ Mage::throwException(Mage::helper('capayable')->__('Invalid amount for authorize.'));
79
+ }
80
+
81
+ // Convert amount to cents
82
+ $amount = $this->getHelper()->convertToCents($amount);
83
+ $_order = $payment->getOrder();
84
+ // Load saved capayable customer if exists. Otherwise load empty model.
85
+ $capayableCustomer = Mage::getModel('capayable/customer')->loadByEmail($_order->getCustomerEmail());
86
+
87
+ // Throw exception if capayable can't provide customer credit
88
+ if(!$this->checkCredit($capayableCustomer, $amount)) {
89
+ throw new Mage_Payment_Model_Info_Exception(Mage::helper('capayable')->__("Can't authorize capayable payment."));
90
+ }
91
+
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * Assign data to info model instance
97
+ * Save capayable customer
98
+ *
99
+ * @param mixed $data
100
+ * @return Mage_Payment_Model_Info
101
+ */
102
+ public function assignData($data)
103
+ {
104
+ if (!($data instanceof Varien_Object)) {
105
+ $data = new Varien_Object($data);
106
+ }
107
+
108
+ $quote = $this->getInfoInstance()->getQuote();
109
+ $address = $quote->getBillingAddress();
110
+
111
+ if(!$quote->getCustomerMiddlename()) {
112
+ $quote->setCustomerMiddlename($data->getCustomerMiddlename());
113
+ }
114
+ if(!$quote->getCustomerGender()) {
115
+ $quote->setCustomerGender($data->getCustomerGender());
116
+ }
117
+
118
+ // Convert date format
119
+ $dob = $quote->getCustomerDob() ? $quote->getCustomerDob() : $data->getCustomerDob();
120
+ $dob = Mage::app()->getLocale()->date($dob, null, null, false)->toString('yyyy-MM-dd 00:00:00');
121
+ $data->setCustomerDob($dob);
122
+ $quote->setCustomerDob($dob);
123
+
124
+ $capayableCustomer = Mage::getModel('capayable/customer')->loadByEmail($quote->getCustomerEmail());
125
+
126
+ /**
127
+ * If capayable customer doesn't exist fill new customer data from quote data.
128
+ * Otherwise rewrite saved customer fields from form data.
129
+ */
130
+ if(!$capayableCustomer->getId()) {
131
+ $capayableCustomer
132
+ ->setCustomerEmail($quote->getCustomerEmail())
133
+ ->setCustomerLastname($quote->getCustomerLastname())
134
+ ->setCustomerMiddlename($quote->getCustomerMiddlename())
135
+ ->setCustomerGender($quote->getCustomerGender())
136
+ ->setCustomerDob($quote->getCustomerDob())
137
+ ->setStreet($data->getStreet())
138
+ ->setHouseNumber((int) $data->getHouseNumber())
139
+ ->setHouseSuffix($data->getHouseSuffix())
140
+ ->setPostcode($address->getPostcode())
141
+ ->setCity($address->getCity())
142
+ ->setCountryId($address->getCountryId())
143
+ ->setTelephone($address->getTelephone())
144
+ ->setFax($address->getFax())
145
+ ->setIsCorporation($data->getIsCorporation())
146
+ ->setCorporationName($data->getCorporationName())
147
+ ->setCocNumber($data->getCocNumber());
148
+ } else {
149
+ $capayableCustomer->addData($data->getData());
150
+ }
151
+
152
+ // Validate capayable customer required fields
153
+ $result = $capayableCustomer->validate();
154
+
155
+ if (true !== $result && is_array($result)) {
156
+ throw new Mage_Payment_Model_Info_Exception(implode(', ', $result));
157
+ }
158
+
159
+ // Save capayable customer to 'capayable/customer' table
160
+ $capayableCustomer->save();
161
+
162
+ $this->getInfoInstance()->addData($data->getData());
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Customer credit check with Capayable.
169
+ * Can take quote or order object.
170
+ *
171
+ * @param Tritac_Capayable_Model_Customer $_customer
172
+ * @param float $amount
173
+ * @param bool $isFinal
174
+ * @return bool|Tritac_CapayableApiClient_Models_CreditCheckResponse
175
+ */
176
+ public function checkCredit(Tritac_Capayable_Model_Customer $_customer, $amount, $isFinal = false)
177
+ {
178
+ /**
179
+ * Initialize new request model and fill all requested fields
180
+ */
181
+ $req = new Tritac_CapayableApiClient_Models_CreditCheckRequest();
182
+ $req->setLastName($_customer->getCustomerLastname());
183
+ $req->setInitials($_customer->getCustomerMiddlename());
184
+
185
+ $gender = Tritac_CapayableApiClient_Enums_Gender::UNKNOWN;
186
+ if($_customer->getCustomerGender() == 1) {
187
+ $gender = Tritac_CapayableApiClient_Enums_Gender::MALE;
188
+ }elseif($_customer->getCustomerGender() == 2) {
189
+ $gender = Tritac_CapayableApiClient_Enums_Gender::FEMALE;
190
+ }
191
+ $req->setGender($gender);
192
+ $req->setBirthDate($_customer->getCustomerDob());
193
+ $req->setStreetName($_customer->getStreet());
194
+ $req->setHouseNumber($_customer->getHouseNumber());
195
+ $req->setHouseNumberSuffix($_customer->getHouseSuffix());
196
+ $req->setZipCode($_customer->getPostcode());
197
+ $req->setCity($_customer->getCity());
198
+ $req->setCountryCode($_customer->getCountryId());
199
+ $req->setPhoneNumber($_customer->getTelephone());
200
+ $req->setFaxNumber($_customer->getFax());
201
+ $req->setEmailAddress($_customer->getCustomerEmail());
202
+ $req->setIsCorporation((bool) $_customer->getIsCorporation());
203
+ $req->setCocNumber($_customer->getCocNumber());
204
+ $req->setCorporationName($_customer->getCorporationName());
205
+ $req->setIsFinal($isFinal);
206
+ $req->setClaimAmount($amount);
207
+
208
+ $result = $this->_client->doCreditCheck($req);
209
+
210
+ /**
211
+ * If request is final return result array which contain transaction id.
212
+ */
213
+ if($isFinal) {
214
+ return $result;
215
+ }
216
+
217
+ return $result->getIsAccepted();
218
+ }
219
+
220
+ /**
221
+ * Post new invoice to Capayable
222
+ *
223
+ * @param $invoice
224
+ * @return mixed
225
+ */
226
+ public function processApiInvoice($invoice)
227
+ {
228
+ // Initialize new api invoice
229
+ $apiInvoice = new Tritac_CapayableApiClient_Models_Invoice();
230
+ // Set required information
231
+ $apiInvoice->setTransactionNumber($invoice->getTransactionId());
232
+ $apiInvoice->setInvoiceNumber($invoice->getId());
233
+ $apiInvoice->setInvoiceAmount($this->getHelper()->convertToCents($invoice->getGrandTotal()));
234
+ $apiInvoice->setInvoiceDescription(Mage::helper('capayable')->__('Order').' '.$invoice->getOrder()->getIncrementId());
235
+ // Register new invoice with Capayable
236
+ $isAccepted = $this->_client->registerInvoice($apiInvoice);
237
+
238
+ return $isAccepted;
239
+ }
240
+ }
app/code/community/Tritac/Capayable/Model/Resource/Customer.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Capayable customer resource model
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ class Tritac_Capayable_Model_Resource_Customer extends Mage_Core_Model_Resource_DB_Abstract {
12
+
13
+ protected function _construct()
14
+ {
15
+ $this->_init('capayable/customer', 'entity_id');
16
+ }
17
+
18
+ /**
19
+ * Load customer data by customer email
20
+ *
21
+ * @param Tritac_Capayable_Model_Customer $customer
22
+ * @param $email
23
+ * @return $this
24
+ */
25
+ public function loadByEmail(Tritac_Capayable_Model_Customer $customer, $email)
26
+ {
27
+
28
+ $adapter = $this->_getReadAdapter();
29
+ $bind = array('customer_email' => $email);
30
+ $select = $adapter->select()
31
+ ->from($this->getMainTable(), array($this->getIdFieldName()))
32
+ ->where('customer_email = :customer_email');
33
+
34
+ $entityId = $adapter->fetchOne($select, $bind);
35
+ if ($entityId) {
36
+ $this->load($customer, $entityId);
37
+ } else {
38
+ $customer->setData(array());
39
+ }
40
+
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * Load customer data by customer id
46
+ *
47
+ * @param Tritac_Capayable_Model_Customer $customer
48
+ * @param $customerId
49
+ * @return $this
50
+ */
51
+ public function loadByCustomerId(Tritac_Capayable_Model_Customer $customer, $customerId)
52
+ {
53
+
54
+ $adapter = $this->_getReadAdapter();
55
+ $bind = array('customer_id' => $customerId);
56
+ $select = $adapter->select()
57
+ ->from($this->getMainTable(), array($this->getIdFieldName()))
58
+ ->where('customer_id = :customer_id');
59
+
60
+ $entityId = $adapter->fetchOne($select, $bind);
61
+ if ($entityId) {
62
+ $this->load($customer, $entityId);
63
+ } else {
64
+ $customer->setData(array());
65
+ }
66
+
67
+ return $this;
68
+ }
69
+ }
app/code/community/Tritac/Capayable/Model/Resource/Customer/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Tritac_Capayable_Model_Resource_Customer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
10
+
11
+ protected function _construct() {
12
+ $this->_init('capayable/customer');
13
+ }
14
+ }
app/code/community/Tritac/Capayable/Model/Resource/Setup.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Capayable setup model
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ class Tritac_Capayable_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {
12
+
13
+ }
app/code/community/Tritac/Capayable/etc/config.xml ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Tritac
5
+ * @package Tritac_Capayable
6
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Tritac_Capayable>
13
+ <version>1.0.0</version>
14
+ </Tritac_Capayable>
15
+ </modules>
16
+
17
+ <global>
18
+ <blocks>
19
+ <capayable>
20
+ <class>Tritac_Capayable_Block</class>
21
+ </capayable>
22
+ </blocks>
23
+ <models>
24
+ <capayable>
25
+ <class>Tritac_Capayable_Model</class>
26
+ <resourceModel>capayable_resource</resourceModel>
27
+ </capayable>
28
+ <capayable_resource>
29
+ <class>Tritac_Capayable_Model_Resource</class>
30
+ <entities>
31
+ <customer>
32
+ <table>capayable_customer</table>
33
+ </customer>
34
+ </entities>
35
+ </capayable_resource>
36
+ </models>
37
+ <helpers>
38
+ <capayable>
39
+ <class>Tritac_Capayable_Helper</class>
40
+ </capayable>
41
+ </helpers>
42
+ <resources>
43
+ <capayable_setup>
44
+ <setup>
45
+ <module>Tritac_Capayable</module>
46
+ <class>Tritac_Capayable_Model_Resource_Setup</class>
47
+ </setup>
48
+ <connection>
49
+ <use>core_setup</use>
50
+ </connection>
51
+ </capayable_setup>
52
+ <capayable_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </capayable_read>
57
+ <capayable_write>
58
+ <connection>
59
+ <use>core_write</use>
60
+ </connection>
61
+ </capayable_write>
62
+ </resources>
63
+
64
+ <fieldsets>
65
+ <sales_convert_quote_payment>
66
+ <test2>
67
+ <to_order_payment>*</to_order_payment>
68
+ </test2>
69
+ </sales_convert_quote_payment>
70
+ </fieldsets>
71
+ </global>
72
+
73
+ <adminhtml>
74
+ <events>
75
+ <sales_order_shipment_save_after>
76
+ <observers>
77
+ <process_invoice_after_shipment>
78
+ <type>singleton</type>
79
+ <class>capayable/observer</class>
80
+ <method>processInvoice</method>
81
+ </process_invoice_after_shipment>
82
+ </observers>
83
+ </sales_order_shipment_save_after>
84
+ <sales_order_load_after>
85
+ <observers>
86
+ <disable_order_invoice>
87
+ <type>singleton</type>
88
+ <class>capayable/observer</class>
89
+ <method>disableOrderInvoice</method>
90
+ </disable_order_invoice>
91
+ </observers>
92
+ </sales_order_load_after>
93
+ </events>
94
+ <translate>
95
+ <modules>
96
+ <Tritac_Capayable>
97
+ <files>
98
+ <default>Tritac_Capayable.csv</default>
99
+ </files>
100
+ </Tritac_Capayable>
101
+ </modules>
102
+ </translate>
103
+ </adminhtml>
104
+
105
+ <frontend>
106
+ <translate>
107
+ <modules>
108
+ <Tritac_Capayable>
109
+ <files>
110
+ <default>Tritac_Capayable.csv</default>
111
+ </files>
112
+ </Tritac_Capayable>
113
+ </modules>
114
+ </translate>
115
+ </frontend>
116
+
117
+ <default>
118
+ <payment>
119
+ <capayable>
120
+ <active>1</active>
121
+ <model>capayable/payment</model>
122
+ <title>Capayable</title>
123
+ <email_customer>1</email_customer>
124
+ <payment_action>authorize</payment_action>
125
+ <sort_order>1</sort_order>
126
+ </capayable>
127
+ </payment>
128
+ </default>
129
+ </config>
app/code/community/Tritac/Capayable/etc/system.xml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Tritac
5
+ * @package Tritac_Capayable
6
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <sections>
12
+ <payment>
13
+ <groups>
14
+ <capayable translate="label" module="capayable">
15
+ <label>Capayable</label>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>2</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ <fields>
22
+ <active translate="label">
23
+ <label>Enabled</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>adminhtml/system_config_source_yesno</source_model>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ </active>
31
+ <public_key translate="label">
32
+ <label>Public Key</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>20</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </public_key>
39
+ <secret_key translate="label">
40
+ <label>Secret Key</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>30</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </secret_key>
47
+ <title translate="label">
48
+ <label>Title</label>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>40</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </title>
55
+ <test translate="label">
56
+ <label>Test Mode</label>
57
+ <frontend_type>select</frontend_type>
58
+ <source_model>adminhtml/system_config_source_yesno</source_model>
59
+ <sort_order>60</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ </test>
64
+ <sort_order translate="label">
65
+ <label>Sort Order</label>
66
+ <frontend_type>text</frontend_type>
67
+ <sort_order>80</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>0</show_in_store>
71
+ <frontend_class>validate-number</frontend_class>
72
+ </sort_order>
73
+ </fields>
74
+ </capayable>
75
+ </groups>
76
+ </payment>
77
+ </sections>
78
+ </config>
app/code/community/Tritac/Capayable/sql/capayable_setup/install-1.0.0.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tritac_Capayable setup script
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ $installer = $this;
12
+
13
+ /* @var $installer Tritac_Capayable_Model_Resource_Setup */
14
+ $installer->startSetup();
15
+
16
+ /**
17
+ * Create table 'capayable_data'
18
+ */
19
+ $table = $installer->getConnection()
20
+ ->newTable($installer->getTable('capayable/customer'))
21
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
22
+ 'identity' => true,
23
+ 'unsigned' => true,
24
+ 'nullable' => false,
25
+ 'primary' => true,
26
+ ), 'Entity Id')
27
+ ->addColumn('customer_email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
28
+ ), 'Customer Email')
29
+ ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
30
+ 'unsigned' => true,
31
+ ), 'Customer Id')
32
+ ->addColumn('customer_lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array(
33
+ ), 'Customer Lastname')
34
+ ->addColumn('customer_middlename', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array(
35
+ ), 'Customer Initials')
36
+ ->addColumn('customer_gender', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
37
+ ), 'Customer Gender')
38
+ ->addColumn('customer_dob', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
39
+ ), 'Customer Dob')
40
+ ->addColumn('street', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array(
41
+ ), 'Street')
42
+ ->addColumn('house_number', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
43
+ ), 'House Number')
44
+ ->addColumn('house_suffix', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array(
45
+ ), 'House Number')
46
+ ->addColumn('postcode', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
47
+ ), 'Postcode')
48
+ ->addColumn('city', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array(
49
+ ), 'City')
50
+ ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array(
51
+ ), 'Country Id')
52
+ ->addColumn('telephone', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
53
+ ), 'Telephone')
54
+ ->addColumn('fax', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
55
+ ), 'Fax')
56
+ ->addColumn('is_corporation', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
57
+ 'unsigned' => true,
58
+ 'nullable' => false,
59
+ 'default' => '0',
60
+ ), 'Is Corporation')
61
+ ->addColumn('corporation_name', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array(
62
+ ), 'Corporation Name')
63
+ ->addColumn('coc_number', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
64
+ ), 'Chamber of Commerce number')
65
+ ->addIndex($installer->getIdxName('capayable/customer', array('customer_id')),
66
+ array('customer_id'))
67
+ ->addIndex($installer->getIdxName('capayable/customer', array('customer_email')),
68
+ array('customer_email'))
69
+ ->setComment('Capayable Customer Data');
70
+
71
+ $installer->getConnection()->createTable($table);
72
+
73
+ $installer->endSetup();
app/design/frontend/base/default/template/capayable/form.phtml ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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@magentocommerce.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.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_code = $this->getMethodCode();
29
+ $_quote = $this->getQuote();
30
+ $_customer = $this->getCustomer();
31
+ $isLoggedIn = Mage::helper('customer')->isLoggedIn();
32
+ ?>
33
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
34
+ <?php if(!$isLoggedIn): ?>
35
+ <?php if(!$_quote->getCustomerMiddlename()): ?>
36
+ <li>
37
+ <label for="<?php echo $_code?>_middlename" class="required"><em>*</em><?php echo $this->__('Middle name (initials)')?></label>
38
+ <div class="input-box">
39
+ <input type="text" id="<?php echo $_code?>_middlename" name="payment[customer_middlename]" class="input-text required-entry" value="" />
40
+ </div>
41
+ </li>
42
+ <?php endif ?>
43
+ <?php if(!$_quote->getCustomerDob()): ?>
44
+ <li>
45
+ <label for="<?php echo $_code?>_month" class="required"><em>*</em><?php echo $this->__('Date of Birth') ?></label>
46
+ <div class="input-box capayable-customer-dob customer-dob">
47
+ <?php
48
+ $_dob = $this->getLayout()->createBlock('customer/widget_dob');
49
+ $_dob->setDateInput('d',
50
+ '<div class="dob-day">
51
+ <input type="text" id="day" name="payment[day]" value="' . $_dob->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" />
52
+ <label for="' . $_code . '_day">' . $this->__('DD') . '</label>
53
+ </div>'
54
+ );
55
+
56
+ $_dob->setDateInput('m',
57
+ '<div class="dob-month">
58
+ <input type="text" id="' . $_code . '_month" name="payment[month]" value="' . $_dob->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" />
59
+ <label for="' . $_code . '_month">' . $this->__('MM') . '</label>
60
+ </div>'
61
+ );
62
+
63
+ $_dob->setDateInput('y',
64
+ '<div class="dob-year">
65
+ <input type="text" id="' . $_code . '_year" name="payment[year]" value="' . $_dob->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" />
66
+ <label for="' . $_code . '_year">' . $this->__('YYYY') . '</label>
67
+ </div>'
68
+ );
69
+
70
+ echo $_dob->getSortedDateInputs();
71
+ ?>
72
+ <div class="dob-full" style="display:none;">
73
+ <input type="hidden" id="<?php echo $_code ?>_dob" name="payment[customer_dob]" />
74
+ </div>
75
+
76
+ <div class="validation-advice" style="display:none;"></div>
77
+ </div>
78
+ <script type="text/javascript">
79
+ //<![CDATA[
80
+ var capayable_customer_dob = new Varien.DOB('.capayable-customer-dob', true, '<?php echo $_dob->getDateFormat() ?>');
81
+ //]]>
82
+ </script>
83
+ </li>
84
+ <?php endif ?>
85
+ <?php if(!$_quote->getCustomerGender()): ?>
86
+ <li>
87
+ <label for="<?php echo $_code?>_gender" class="required"><em>*</em><?php echo $this->__('Gender') ?></label>
88
+ <div class="input-box">
89
+ <select id="<?php echo $_code?>_gender" name="payment[customer_gender]" title="<?php echo $this->__('Gender') ?>" class="validate-select">
90
+ <?php
91
+ $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
92
+ ?>
93
+ <?php foreach ($options as $option):?>
94
+ <option value="<?php echo $option['value'] ?>"><?php echo $option['label'] ?></option>
95
+ <?php endforeach;?>
96
+ </select>
97
+ </div>
98
+ </li>
99
+ <?php endif ?>
100
+ <?php endif ?>
101
+ <li>
102
+ <label for="<?php echo $_code?>_street" class="required"><em>*</em><?php echo $this->__('Street')?></label>
103
+ <div class="input-box">
104
+ <input type="text" id="<?php echo $_code?>_street" name="payment[street]" class="input-text required-entry" value="<?php if($_customer->getStreet() && $isLoggedIn) echo $_customer->getStreet()?>" />
105
+ </div>
106
+ </li>
107
+ <li>
108
+ <label for="<?php echo $_code?>_house_number" class="required"><em>*</em><?php echo $this->__('House number')?></label>
109
+ <div class="input-box">
110
+ <input type="text" id="<?php echo $_code?>_house_number" name="payment[house_number]" class="input-text required-entry" value="<?php if($_customer->getHouseNumber() && $isLoggedIn) echo $_customer->getHouseNumber()?>" />
111
+ </div>
112
+ </li>
113
+ <li>
114
+ <label for="<?php echo $_code?>_house_suffix"><?php echo $this->__('House number suffix')?></label>
115
+ <div class="input-box">
116
+ <input type="text" id="<?php echo $_code?>_house_suffix" name="payment[house_suffix]" class="input-text" value="<?php if($_customer->getHouseSuffix() && $isLoggedIn) echo $_customer->getHouseSuffix()?>" />
117
+ </div>
118
+ </li>
119
+ <li>
120
+ <label for="<?php echo $_code?>_is_corporation"><?php echo $this->__('Is Corporation')?></label>
121
+ <div class="input-box">
122
+ <select name="payment[is_corporation]" id="<?php echo $_code ?>_is_corporation">
123
+ <option value="0" <?php if($_customer->getIsCorporation() == 0 && $isLoggedIn): ?>selected="selected"<?php endif ?>><?php echo $this->__('No')?></option>
124
+ <option value="1" <?php if($_customer->getIsCorporation() == 1 && $isLoggedIn): ?>selected="selected"<?php endif ?>><?php echo $this->__('Yes')?></option>
125
+ </select>
126
+ </div>
127
+ </li>
128
+ <li>
129
+ <label for="<?php echo $_code?>_corporation_name"><?php echo $this->__('Corporation Name')?></label>
130
+ <div class="input-box">
131
+ <input type="text" id="<?php echo $_code?>_corporation_name" name="payment[corporation_name]" class="input-text" value="<?php if($_customer->getCorporationName() && $isLoggedIn) echo $_customer->getCorporationName()?>" />
132
+ </div>
133
+ </li>
134
+ <li>
135
+ <label for="<?php echo $_code?>_coc_number"><?php echo $this->__('Chamber of Commerce Number')?></label>
136
+ <div class="input-box">
137
+ <input type="text" id="<?php echo $_code?>_coc_number" name="payment[coc_number]" class="input-text" value="<?php if($_customer->getCocNumber() && $isLoggedIn) echo $_customer->getCocNumber()?>" />
138
+ </div>
139
+ </li>
140
+ </ul>
app/design/frontend/base/default/template/capayable/info.phtml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ echo $this->getMethod()->getTitle();
app/etc/modules/Tritac_Capayable.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Tritac
5
+ * @package Tritac_Capayable
6
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Tritac_Capayable>
13
+ <active>true</active>
14
+ <codePool>community</codePool>
15
+ </Tritac_Capayable>
16
+ </modules>
17
+ </config>
app/locale/nl_NL/Tritac_Capayable.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Middle name (initials)","Initialen"
2
+ "Date of Birth","Geboortedatum"
3
+ "Day","Dag"
4
+ "DD","DD"
5
+ "Month","Maand"
6
+ "MM","MM"
7
+ "Year","Jaar"
8
+ "YYYY","JJJJ"
9
+ "Gender","Geslacht"
10
+ "Street","Straatnaam"
11
+ "House number","Huisnummer"
12
+ "House number suffix","Huisnummer toevoeging"
13
+ "Is Corporation","Bedrijf"
14
+ "No","Nee"
15
+ "Yes","Ja"
16
+ "Corporation Name", "Bedrijfsnaam"
17
+ "Chamber of Commerce Number","KvK-nummer"
lib/Tritac/CapayableApiClient/AddTrustExternalCARoot.crt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
3
+ MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
4
+ IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
5
+ MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
6
+ FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
7
+ bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
8
+ dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
9
+ H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
10
+ uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
11
+ mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
12
+ a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
13
+ E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
14
+ WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
15
+ VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
16
+ Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
17
+ cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
18
+ IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
19
+ AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
20
+ YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
21
+ 6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
22
+ Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
23
+ c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
24
+ mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
25
+ -----END CERTIFICATE-----
lib/Tritac/CapayableApiClient/Client.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Client {
3
+
4
+ private $environment;
5
+ private $tenant;
6
+ private $certificate;
7
+
8
+ private $apiUrl;
9
+ private $apiKey;
10
+ private $apiSecret;
11
+
12
+ const FIDDLER_PROXY = '127.0.0.1:8888';
13
+ const USE_FIDDLER = false;
14
+ const FIDDLER_CERTIFICATE_PATH = 'fiddler.crt';
15
+
16
+ const ACC_URL = 'http://capayable-api-acc.tritac.com';
17
+ const TEST_URL = 'https://capayable-api-test.tritac.com';
18
+ const PROD_URL = 'https://capayable-api.tritac.com';
19
+
20
+ const VERSION_PATH = '/v1';
21
+ const CERTIFICATE_PATH = 'AddTrustExternalCARoot.crt';
22
+
23
+ const CREDITCHECK_PATH = '/creditcheck';
24
+ const INVOICE_PATH = '/invoice';
25
+
26
+ public function __construct($apiKey, $apiSecret, $env = null)
27
+ {
28
+ if($env == null || $env == Tritac_CapayableApiClient_Enums_Environment::PROD) {
29
+ $this->apiUrl = self::PROD_URL;
30
+ } elseif($env == Tritac_CapayableApiClient_Enums_Environment::TEST) {
31
+ $this->apiUrl = self::TEST_URL;
32
+ } elseif($env == Tritac_CapayableApiClient_Enums_Environment::TEST) {
33
+ $this->apiUrl = self::ACC_URL;
34
+ }
35
+
36
+ $this->environment = $env;
37
+ $this->apiKey = $apiKey;
38
+ $this->apiSecret = $apiSecret;
39
+ $this->certificate = __DIR__ . DIRECTORY_SEPARATOR . (self::USE_FIDDLER ? self::FIDDLER_CERTIFICATE_PATH : self::CERTIFICATE_PATH);
40
+ }
41
+
42
+ public function doCreditCheck(Tritac_CapayableApiClient_Models_CreditCheckRequest $request)
43
+ {
44
+ $args = $request->toArray();
45
+ if(!$request->getIsCorporation()){
46
+ unset($args['CocNumber']);
47
+ unset($args['CorporationName']);
48
+ }
49
+
50
+ $path = self::VERSION_PATH . self::CREDITCHECK_PATH;
51
+
52
+ $response = json_decode($this->makeRequest(Tritac_CapayableApiClient_Enums_HttpMethod::GET, $path, $this->buildQueryString($args, $path)));
53
+
54
+ return new Tritac_CapayableApiClient_Models_CreditCheckResponse($response->IsAccepted, $response->TransactionNumber);
55
+ }
56
+
57
+ public function registerInvoice(Tritac_CapayableApiClient_Models_Invoice $invoice)
58
+ {
59
+ $args = $invoice->toArray();
60
+ $path = self::VERSION_PATH . self::INVOICE_PATH;
61
+
62
+ $response = json_decode($this->makeRequest(Tritac_CapayableApiClient_Enums_HttpMethod::GET, $path, $this->buildQueryString($args, $path)));
63
+
64
+ return $response->IsAccepted;
65
+ }
66
+
67
+ /* Private methods */
68
+
69
+ private function makeRequest($method, $url, $queryString = '', $content = null)
70
+ {
71
+ $request = curl_init();
72
+
73
+ // Create the required Http headers
74
+ $headers = $this->buildHeaders($method, $content);
75
+
76
+ if(self::USE_FIDDLER)
77
+ {
78
+ // We use this to redirect the request through a local proxy and trace it with fiddler
79
+ curl_setopt($request, CURLOPT_PROXY, self::FIDDLER_PROXY);
80
+ }
81
+
82
+ // Set the Url
83
+ curl_setopt($request, CURLOPT_URL, $this->apiUrl . $url . $queryString);
84
+
85
+ // Add the headers and hmac auth.
86
+ curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
87
+
88
+ // Return the response as a string
89
+ curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
90
+
91
+ // Set custom request method because curl has no setting for PUT and DELETE
92
+ curl_setopt($request, CURLOPT_CUSTOMREQUEST, $method);
93
+
94
+ // Make the headers accessible for debugging purposes
95
+ curl_setopt($request, CURLINFO_HEADER_OUT, true);
96
+
97
+ // Point curl to the correct certificate.
98
+ // See: http://stackoverflow.com/questions/6400300/php-curl-https-causing-exception-ssl-certificate-problem-verify-that-the-ca-cer
99
+ curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true);
100
+ curl_setopt($request, CURLOPT_CAINFO, $this->certificate);
101
+
102
+ // If we have a request body send it too
103
+ if(strlen($content) > 0)
104
+ curl_setopt($request, CURLOPT_POSTFIELDS, $content);
105
+
106
+ // Make the request
107
+ $response = curl_exec($request);
108
+
109
+ // Get the status code
110
+ $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
111
+
112
+
113
+
114
+ // Check for errors
115
+ // First we check if the response is missing which will probably be caused by a cURL error
116
+ // After this the check if there are not HTTP errors (status codes other than 200-206)
117
+ if ($response === false)
118
+ {
119
+ $error = curl_error($request);
120
+ curl_close($request);
121
+ throw new Exception('cURL error: ' . $error);
122
+ }
123
+ else if($status < 200 || $status > 206)
124
+ {
125
+ $headers = curl_getinfo($request, CURLINFO_HEADER_OUT);
126
+ $message = json_decode($response);
127
+
128
+ curl_close($request);
129
+
130
+ throw new Exception('Output headers: '. "\n" . $headers ."\n\n".
131
+ 'Content: ' . $content ."\n\n".
132
+ 'Unexpected status code [' . $status . ']. The server returned the following message: "' . $message->Message . '"');
133
+ }
134
+ else
135
+ {
136
+ curl_close($request);
137
+
138
+ return $response;
139
+ }
140
+ }
141
+
142
+ private function buildHeaders($method, $content = null)
143
+ {
144
+ $headers = array(
145
+ 'Accept: application/json',
146
+ 'Content-Type: application/json; charset=utf-8',
147
+ 'Content-Length: ' . strlen($content),
148
+ );
149
+
150
+ return $headers;
151
+ }
152
+
153
+ private function buildQueryString(array $args, $path)
154
+ {
155
+
156
+ $hash = $this->getHash($args, $path);
157
+ $args['signature'] = $hash;
158
+ $args['key'] = $this->apiKey;
159
+ $args['timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
160
+ return $this->encodeQueryString($args);
161
+ }
162
+
163
+ private function getHash(array $args, $path){
164
+ // Copy the array
165
+ $sortedArgs = $args;
166
+
167
+ // Sort it
168
+ ksort($sortedArgs);
169
+
170
+ $sortedArgs['key'] = $this->apiKey;
171
+ $sortedArgs['timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
172
+
173
+ $representation = $path . urldecode($this->encodeQueryString($sortedArgs));
174
+ $hash = hash_hmac('sha256', utf8_encode($representation), utf8_encode($this->apiSecret), true);
175
+
176
+ return base64_encode($hash);
177
+ }
178
+
179
+ private function encodeQueryString(array $args) {
180
+ $queryString = (count($args) > 0) ? '?' . http_build_query($args) : '';
181
+
182
+ // .Net does not seem to like the /?foo[0]=bar&foo[1]=baz notation so we
183
+ // convert it to /?foo=bar&foo=baz
184
+ return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
185
+ }
186
+ }
lib/Tritac/CapayableApiClient/Enums/Environment.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Enums_Environment {
3
+
4
+ const ACC = 0;
5
+ const TEST = 1;
6
+ const PROD = 2;
7
+
8
+ }
lib/Tritac/CapayableApiClient/Enums/Gender.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Enums_Gender {
3
+
4
+ const MALE = 'MALE';
5
+ const FEMALE = 'FEMALE';
6
+ const UNKNOWN = 'UNKNOWN';
7
+
8
+ }
lib/Tritac/CapayableApiClient/Enums/HttpMethod.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Enums_HttpMethod {
3
+
4
+ const GET = 'GET';
5
+ const POST = 'POST';
6
+ const PUT = 'PUT';
7
+ const DELETE = 'DELETE';
8
+
9
+ }
lib/Tritac/CapayableApiClient/Models/BaseModel.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ abstract class Tritac_CapayableApiClient_Models_BaseModel {
3
+
4
+ public static $typeMap = array(
5
+
6
+ );
7
+
8
+ public function getTypeName()
9
+ {
10
+ return get_called_class();
11
+ }
12
+
13
+ public function toArray()
14
+ {
15
+ $vars = get_object_vars($this);
16
+ $arr = array();
17
+ foreach($vars as $key => $value) {
18
+ $newKey = ucfirst($key);
19
+ $getter = 'get' . $newKey;
20
+ $value = $this->{$getter}();
21
+
22
+ if(is_bool($value)) {
23
+ $arr[$newKey] = ($value) ? 'True' : 'False';
24
+ } elseif(!empty($value)) {
25
+ $arr[$newKey] = $value;
26
+ }
27
+
28
+ }
29
+
30
+ return $arr;
31
+ }
32
+ }
lib/Tritac/CapayableApiClient/Models/CreditCheckRequest.php ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Models_CreditCheckRequest extends Tritac_CapayableApiClient_Models_BaseModel
3
+ {
4
+ protected $lastName;
5
+ protected $initials;
6
+ protected $gender; // https://en.wikipedia.org/wiki/ISO/IEC_5218
7
+ protected $birthDate;
8
+ protected $streetName;
9
+ protected $houseNumber;
10
+ protected $houseNumberSuffix;
11
+ protected $zipCode;
12
+ protected $city;
13
+ protected $countryCode;
14
+ protected $phoneNumber;
15
+ protected $faxNumber;
16
+ protected $emailAddress;
17
+ protected $isCorporation;
18
+ protected $corporationName;
19
+ protected $cocNumber;
20
+ protected $isFinal;
21
+ protected $claimAmount;
22
+
23
+ public function __construct()
24
+ {
25
+ $this->lastName = '';
26
+ $this->initials = '';
27
+ $this->gender = Tritac_CapayableApiClient_Enums_Gender::UNKNOWN; // https://en.wikipedia.org/wiki/ISO/IEC_5218
28
+ $this->birthDate = new DateTime();
29
+ $this->streetName = '';
30
+ $this->houseNumber = '';
31
+ $this->houseNumberSuffix = '';
32
+ $this->zipCode = '';
33
+ $this->city = '';
34
+ $this->countryCode = '';
35
+ $this->phoneNumber = '';
36
+ $this->faxNumber = '';
37
+ $this->emailAddress = '';
38
+ $this->isCorporation = false;
39
+ $this->corporationName = '';
40
+ $this->cocNumber = '';
41
+ $this->isFinal = false;
42
+ $this->claimAmount = 0;
43
+ }
44
+
45
+ function getLastName() { return $this->lastName; }
46
+ function setLastName($lastName) {
47
+
48
+ if(strlen($lastName) > 150) {
49
+ throw new Exception('Last name may not exceed 150 characters');
50
+ }
51
+
52
+ $this->lastName = $lastName;
53
+ }
54
+
55
+
56
+ function getInitials() { return $this->initials; }
57
+ function setInitials($initials) {
58
+
59
+ if(strlen($initials) > 10) {
60
+ throw new Exception('Initials may not exceed 10 characters');
61
+ }
62
+
63
+ $this->initials = $initials;
64
+ }
65
+
66
+
67
+ function getGender() { return $this->gender; }
68
+ function setGender($gender) {
69
+ if(
70
+ $gender != Tritac_CapayableApiClient_Enums_Gender::MALE &&
71
+ $gender != Tritac_CapayableApiClient_Enums_Gender::FEMALE &&
72
+ $gender != Tritac_CapayableApiClient_Enums_Gender::UNKNOWN
73
+ ) {
74
+ throw new Exception('Gender invalid, please use CapayableApiClient\Enums\Gender');
75
+ }
76
+ $this->gender = $gender;
77
+ }
78
+
79
+ function getBirthDate() { return $this->birthDate->format('Y-m-d'); }
80
+ function getBirthDateAsDateTime() { return $this->birthDate; }
81
+ function setBirthDate($birthDate) {
82
+
83
+ $this->birthDate = new DateTime($birthDate);
84
+ }
85
+ function setBirthDateAsDateTime(DateTime $birthDate) {
86
+ $this->birthDate = $birthDate;
87
+ }
88
+
89
+ function getStreetName() { return $this->streetName; }
90
+ function setStreetName($streetName) {
91
+
92
+ if(strlen($streetName) > 150) {
93
+ throw new Exception('Street name may not exceed 150 characters');
94
+ }
95
+
96
+ $this->streetName = $streetName;
97
+ }
98
+
99
+ function getHouseNumber() { return $this->houseNumber; }
100
+ function setHouseNumber($houseNumber) {
101
+
102
+ if(!is_numeric($houseNumber)) {
103
+ throw new Exception('House number must be numeric');
104
+ }
105
+
106
+ $this->houseNumber = $houseNumber;
107
+ }
108
+
109
+ function getHouseNumberSuffix() { return $this->houseNumberSuffix; }
110
+ function setHouseNumberSuffix($houseNumberSuffix) {
111
+
112
+ if(strlen($houseNumberSuffix) > 10) {
113
+ throw new Exception('House number suffix may not exceed 10 characters');
114
+ }
115
+
116
+ $this->houseNumberSuffix = $houseNumberSuffix;
117
+
118
+ }
119
+
120
+ function getZipCode() { return $this->zipCode; }
121
+ function setZipCode($zipCode) {
122
+
123
+ if(strlen($zipCode) > 20) {
124
+ throw new Exception('Zip code may not exceed 20 characters');
125
+ }
126
+
127
+ $this->zipCode = $zipCode;
128
+ }
129
+
130
+ function getCity() { return $this->city; }
131
+ function setCity($city) {
132
+
133
+ if(strlen($city) > 150) {
134
+ throw new Exception('Zip code may not exceed 150 characters');
135
+ }
136
+
137
+ $this->city = $city;
138
+ }
139
+
140
+ function getCountryCode() { return $this->countryCode; }
141
+ function setCountryCode($countryCode) {
142
+
143
+ if(strlen($countryCode) > 2) {
144
+ throw new Exception('Country code may not exceed 2 characters');
145
+ }
146
+
147
+ $this->countryCode = $countryCode;
148
+
149
+ }
150
+
151
+ function getPhoneNumber() { return $this->phoneNumber; }
152
+ function setPhoneNumber($phoneNumber) {
153
+
154
+ if(strlen($phoneNumber) > 20) {
155
+ throw new Exception('Phone number may not exceed 20 characters');
156
+ }
157
+
158
+ $this->phoneNumber = $phoneNumber;
159
+
160
+ }
161
+
162
+ function getFaxNumber() { return $this->faxNumber; }
163
+ function setFaxNumber($faxNumber) {
164
+
165
+ if(strlen($faxNumber) > 20) {
166
+ throw new Exception('Fax number may not exceed 20 characters');
167
+ }
168
+
169
+ $this->faxNumber = $faxNumber;
170
+
171
+ }
172
+
173
+ function getIsCorporation() { return $this->isCorporation; }
174
+ function setIsCorporation($isCorporation) {
175
+
176
+ if(!is_bool($isCorporation)){
177
+ throw new Exception('Is corporation must be a boolean');
178
+ }
179
+
180
+ $this->isCorporation = $isCorporation;
181
+ }
182
+
183
+ function getEmailAddress() { return $this->emailAddress; }
184
+ function setEmailAddress($emailAddress) {
185
+
186
+ if(!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)){
187
+ throw new Exception('Must be a valid email');
188
+ }
189
+
190
+ $this->emailAddress = $emailAddress;
191
+ }
192
+
193
+ function getCorporationName() { return $this->corporationName; }
194
+ function setCorporationName($corporationName) {
195
+ $this->corporationName = $corporationName;
196
+ }
197
+
198
+ function getCocNumber() { return $this->cocNumber; }
199
+ function setCocNumber($cocNumber) {
200
+
201
+ if(strlen($cocNumber) > 20) {
202
+ throw new Exception('Chamber of commerce number may not exceed 20 characters');
203
+ }
204
+
205
+ $this->cocNumber = $cocNumber;
206
+
207
+ }
208
+
209
+ function getIsFinal() { return $this->isFinal; }
210
+ function setIsFinal($isFinal) {
211
+
212
+ if(!is_bool($isFinal)) {
213
+ throw new Exception('Is final must be a boolean');
214
+ }
215
+
216
+ $this->isFinal = $isFinal;
217
+ }
218
+
219
+ function getClaimAmount() { return $this->claimAmount; }
220
+ function setClaimAmount($claimAmount) {
221
+
222
+ if(!is_numeric($claimAmount)) {
223
+ throw new Exception('Claim amount must be numeric');
224
+ }
225
+
226
+ $this->claimAmount = $claimAmount;
227
+ }
228
+ }
lib/Tritac/CapayableApiClient/Models/CreditCheckResponse.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Models_CreditCheckResponse extends Tritac_CapayableApiClient_Models_BaseModel
3
+ {
4
+ protected $transactionNumber;
5
+ protected $invoiceNumber;
6
+ protected $invoiceDate;
7
+ protected $invoiceAmount;
8
+ protected $invoiceDescription;
9
+
10
+ public function __construct($isAccepted, $transactionNumber)
11
+ {
12
+ $this->transactionNumber = $transactionNumber;
13
+ $this->isAccepted = $isAccepted;
14
+ }
15
+
16
+ function getTransactionNumber() { return $this->transactionNumber; }
17
+ function getIsAccepted() { return $this->isAccepted; }
18
+ }
lib/Tritac/CapayableApiClient/Models/Invoice.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Tritac_CapayableApiClient_Models_Invoice extends Tritac_CapayableApiClient_Models_BaseModel
3
+ {
4
+ protected $transactionNumber;
5
+ protected $invoiceNumber;
6
+ protected $invoiceDate;
7
+ protected $invoiceAmount;
8
+ protected $invoiceDescription;
9
+
10
+ public function __construct()
11
+ {
12
+ $this->transactionNumber = '';
13
+ $this->invoiceNumber = '';
14
+ $this->invoiceDate = new DateTime();
15
+ $this->invoiceAmount = 0;
16
+ $this->invoiceDescription = '';
17
+ }
18
+
19
+ function getTransactionNumber() { return $this->transactionNumber; }
20
+ function setTransactionNumber($transactionNumber) {
21
+
22
+ if(strlen($transactionNumber) > 32) {
23
+ throw new Exception('Transaction number may not exceed 32 characters');
24
+ }
25
+
26
+ $this->transactionNumber = $transactionNumber;
27
+ }
28
+
29
+ function getInvoiceNumber() { return $this->invoiceNumber; }
30
+ function setInvoiceNumber($invoiceNumber) {
31
+
32
+ if(strlen($invoiceNumber) > 150) {
33
+ throw new Exception('Invoice number may not exceed 150 characters');
34
+ }
35
+
36
+ $this->invoiceNumber = $invoiceNumber;
37
+ }
38
+
39
+ function getInvoiceDate() { return $this->invoiceDate->format('Y-m-d'); }
40
+ function getInvoiceDateAsDateTime() { return $this->invoiceDate; }
41
+ function setInvoiceDate($invoiceDate) {
42
+
43
+ $this->invoiceDate = new DateTime($invoiceDate);
44
+ }
45
+ function setInvoiceDateAsDateTime(DateTime $invoiceDate) {
46
+ $this->invoiceDate = $invoiceDate;
47
+ }
48
+
49
+ function getInvoiceAmount() { return $this->invoiceAmount; }
50
+ function setInvoiceAmount($invoiceAmount) {
51
+
52
+ if(!is_numeric($invoiceAmount)) {
53
+ throw new Exception('Invoice amount must be numeric');
54
+ }
55
+
56
+ $this->invoiceAmount = $invoiceAmount;
57
+ }
58
+
59
+ function getInvoiceDescription() { return $this->invoiceDescription; }
60
+ function setInvoiceDescription($invoiceDescription) {
61
+
62
+ if(strlen($invoiceDescription) > 225) {
63
+ throw new Exception('Invoice description may not exceed 225 characters');
64
+ }
65
+
66
+ $this->invoiceDescription = $invoiceDescription;
67
+ }
68
+ }
lib/Tritac/CapayableApiClient/fiddler.crt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDhTCCAvKgAwIBAgIQ1gnPE4Ebi6VA8yWGI387iDAJBgUrDgMCHQUAMIGLMSsw
3
+ KQYDVQQLEyJDcmVhdGVkIGJ5IGh0dHA6Ly93d3cuZmlkZGxlcjIuY29tMSEwHwYD
4
+ VQQKHhgARABPAF8ATgBPAFQAXwBUAFIAVQBTAFQxOTA3BgNVBAMeMABEAE8AXwBO
5
+ AE8AVABfAFQAUgBVAFMAVABfAEYAaQBkAGQAbABlAHIAUgBvAG8AdDAeFw0xMjA1
6
+ MjkyMjAwMDBaFw0yMzA1MjkyMTU5NTlaMIGLMSswKQYDVQQLEyJDcmVhdGVkIGJ5
7
+ IGh0dHA6Ly93d3cuZmlkZGxlcjIuY29tMSEwHwYDVQQKHhgARABPAF8ATgBPAFQA
8
+ XwBUAFIAVQBTAFQxOTA3BgNVBAMeMABEAE8AXwBOAE8AVABfAFQAUgBVAFMAVABf
9
+ AEYAaQBkAGQAbABlAHIAUgBvAG8AdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
10
+ gYEAqZkiRrcbzq9G4bNxVnkOqPcKIoUQjQ6vbI061JZWn8Ju6X4zayyJ5yYihCmL
11
+ fiR0RlxLwZPRBkjtssMvk6LBUL8hKsNYF3HCQ65q3OKnUU9jp3IvL6Vep/3xcuJD
12
+ oJ4dw9sHAXPe2CTbvPXo9zVsAUuyge0Z3aMoKFxagASzbiUCAwEAAaOB7zCB7DAS
13
+ BgNVHRMBAf8ECDAGAQH/AgEBMBMGA1UdJQQMMAoGCCsGAQUFBwMBMIHABgNVHQEE
14
+ gbgwgbWAEKx6M2aKK2O4CDAn0Ab9WD+hgY4wgYsxKzApBgNVBAsTIkNyZWF0ZWQg
15
+ YnkgaHR0cDovL3d3dy5maWRkbGVyMi5jb20xITAfBgNVBAoeGABEAE8AXwBOAE8A
16
+ VABfAFQAUgBVAFMAVDE5MDcGA1UEAx4wAEQATwBfAE4ATwBUAF8AVABSAFUAUwBU
17
+ AF8ARgBpAGQAZABsAGUAcgBSAG8AbwB0ghDWCc8TgRuLpUDzJYYjfzuIMAkGBSsO
18
+ AwIdBQADgYEAhLKCHLHh+On9LRnuspe0D3ZOuFW33wjBIttTwyo6C+6EyW6aStqf
19
+ ABS3ZujnSgUMzNL9XdROCGdTNB0qNYal4DemO3ls/4zHQXwT0vYP3f57sb9RP1YU
20
+ 8c2qFrrX+UhUMNPN/TyZu4aR4wjt/FtSfQYnwTxhBno2AOn/3vToTls=
21
+ -----END CERTIFICATE-----
lib/Tritac/CapayableApiClient/loader.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // This loader is required to make use of the php __autoload functionality.
4
+
5
+ /*function __autoload($class) {
6
+ $class = str_replace('\\', '/', $class) . '.php';
7
+ require_once($class);
8
+ }*/
9
+
10
+ // Add the class dir to include path
11
+ set_include_path(get_include_path() . PATH_SEPARATOR);
12
+
13
+ // Use default autoload implementation
14
+ spl_autoload_register();
package.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Tritac_Capayable</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Gain your customers trust by allowing them to pay after delivery with Capayable.</summary>
10
+ <description>Gain your customers trust by allowing them to pay after delivery. Using Capayable there will be no additional risks and a substantial increase in sales.&#xD;
11
+ &#xD;
12
+ The trust of your customers will increase by providing multiple payment methods on your webshop. Especially when you provide the customer friendly Capayable pay after delivery method. Aditionally consumers increasingly expect you to provide a way of paying after delivery. They will pick the webshops with the most convenient payment methods. That's where they like to shop the most!&#xD;
13
+ &#xD;
14
+ By fulfilling your customers desires you will realize a substatial gain in online sales. Studies show that an increase of conversion rates up to 30%. This is revenue you don't want to miss! With Capayable pay after delivery you will achieve maximum convenience at your webshop's checkout. You show trust in your customers and they will appreciate it. This way you will work on a healthy relation.&#xD;
15
+ &#xD;
16
+ Keep the risk of default to a minimum with Capayable. During the order process Capayable will assess the solvency of the customer. The result of this assessment will determine if the customer gets the option to pay after delivery. Moreover, the collection of the due payment is Capayable's risk. Customer service at checkout and your financial security go hand in hand.</description>
17
+ <notes>Version 1.0.0</notes>
18
+ <authors><author><name>Capayable</name><user>capayable</user><email>capayable@tritac.com</email></author></authors>
19
+ <date>2014-03-31</date>
20
+ <time>12:04:07</time>
21
+ <contents><target name="mageetc"><dir name="modules"><file name="Tritac_Capayable.xml" hash="7001b4ff4fb879a1186fcd5d2c8e66a9"/></dir></target><target name="magecommunity"><dir name="Tritac"><dir name="Capayable"><dir name="Block"><file name="Form.php" hash="6e7b2763ca0b75f0654d1abf3f8ad997"/><file name="Info.php" hash="a77b42b5730b33e46a3e9168d2080d3f"/></dir><dir name="Helper"><file name="Data.php" hash="e9720cd4bafa9f2edb3d29f41be8aa2e"/></dir><dir name="Model"><file name="Customer.php" hash="7fff9352d16ea5fd730e53b4f29e7aaa"/><file name="Observer.php" hash="82fb183d66462dae19e4e69b5edec99c"/><file name="Payment.php" hash="7fddec277e535d312a21d5f79d06aa2f"/><dir name="Resource"><dir name="Customer"><file name="Collection.php" hash="d3ada6e04cd45cf7722194707ab46b72"/></dir><file name="Customer.php" hash="3e56839b9b93adf24f711cfc6b08cbb1"/><file name="Setup.php" hash="1d6ad9d431cf9a945720ba82d2adf57f"/></dir></dir><dir name="etc"><file name="config.xml" hash="e8bad6825e4fe5cafae01f2aac8d8562"/><file name="system.xml" hash="101d79df6bd9b1b81b9d2aaba30d6cff"/></dir><dir name="sql"><dir name="capayable_setup"><file name="install-1.0.0.php" hash="ff232168a4cbe940430eee93047d1147"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="capayable"><file name="form.phtml" hash="640562045d965035d593fc436ba4f629"/><file name="info.phtml" hash="81523da11b4559b6c2c19710521bc71d"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="nl_NL"><file name="Tritac_Capayable.csv" hash="c5d105f467196d08a07b0847b223699f"/></dir></target><target name="magelib"><dir name="Tritac"><dir name="CapayableApiClient"><file name="AddTrustExternalCARoot.crt" hash="51e14b4c734e450402ea2cf73f2aee0f"/><file name="Client.php" hash="bb34de799643f296c2e5bb424908cbef"/><dir name="Enums"><file name="Environment.php" hash="1c138f029b693bde668e9a5c33b73e8a"/><file name="Gender.php" hash="ad079406a788728980d6142405675cfd"/><file name="HttpMethod.php" hash="f9dc6ddcdef8c7573c726642ef596163"/></dir><dir name="Models"><file name="BaseModel.php" hash="0656176f09813a43eb27cb3a17001c55"/><file name="CreditCheckRequest.php" hash="d804de22a963b8f62f6ef435e31fee0c"/><file name="CreditCheckResponse.php" hash="edebda4e080125af419a09b138447f93"/><file name="Invoice.php" hash="ef8bb4b8f5fd57d2a9f5649b0cd52ad4"/></dir><file name="fiddler.crt" hash="7af0c3cd8b8c816712ee1c6ffd09bc91"/><file name="loader.php" hash="5a7f334b15555740f45c3d54cf826bc3"/></dir></dir></target></contents>
22
+ <compatible/>
23
+ <dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies>
24
+ </package>