├── src
├── logo.gif
├── logo.png
├── img
│ ├── logo.png
│ ├── undo.png
│ ├── trash.png
│ ├── ajax-loader.gif
│ ├── secure-icon.png
│ ├── credit-cards.png
│ └── index.php
├── config.xml
├── README.md
├── lib
│ ├── index.php
│ ├── Simplify
│ │ ├── index.php
│ │ ├── ResourceList.php
│ │ ├── Constants.php
│ │ ├── Object.php
│ │ ├── Authentication.php
│ │ ├── Payment.php
│ │ ├── Exceptions.php
│ │ ├── PaymentsApi.php
│ │ ├── Customer.php
│ │ └── Http.php
│ └── Simplify.php
├── css
│ ├── index.php
│ └── style.css
├── js
│ ├── index.php
│ ├── simplify.form.js
│ └── simplify.js
├── views
│ ├── index.php
│ └── templates
│ │ ├── index.php
│ │ └── hook
│ │ ├── index.php
│ │ ├── order-confirmation.tpl
│ │ └── payment.tpl
├── validation.php
└── simplifycommerce.php
├── README.md
└── licence.txt
/src/logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/logo.gif
--------------------------------------------------------------------------------
/src/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/logo.png
--------------------------------------------------------------------------------
/src/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/logo.png
--------------------------------------------------------------------------------
/src/img/undo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/undo.png
--------------------------------------------------------------------------------
/src/img/trash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/trash.png
--------------------------------------------------------------------------------
/src/img/ajax-loader.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/ajax-loader.gif
--------------------------------------------------------------------------------
/src/img/secure-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/secure-icon.png
--------------------------------------------------------------------------------
/src/img/credit-cards.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siddii/simplify-prestashop-module/master/src/img/credit-cards.png
--------------------------------------------------------------------------------
/src/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | simplifycommerce
4 |
5 |
6 |
7 |
8 |
9 | Warning: Are you sure you want to uninstall this module?
10 | 1
11 | 0
12 | us
13 |
14 |
--------------------------------------------------------------------------------
/src/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Simplify Commerce payment module for PrestaShop
3 |
4 | This plugin adds Simplify Commerce as a payment option on your PrestaShop checkout page.
5 |
6 | ## Installation
7 | 1/ If you haven't done so already, download a release (simplifycommerce.zip) from the menu option above and install the zip file through the PrestaShop admin panel and enable it.
8 |
9 | 2/ Configure the module by adding your API keys on the settings page (Click the 'Configure' link on the module)
10 |
11 | Optionally:
12 |
13 | 1/ Unzip the downloaded source zip file and build your own module zip file by executing an 'ant' command within the root directory.
14 |
15 | 2/ You can install the newly built module (located in the 'dist' folder) as before.
16 |
17 | You can manage your Simplify account (view deposits, perform refunds etc.) using the Simplify dashboard at https://www.simplify.com/commerce/.
18 |
19 | ## License
20 | This software is Open Source, released under the BSD 3-Clause license. See licence.txt for more info.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simplify Commerce payment module for PrestaShop #
2 |
3 | This plugin adds Simplify Commerce as a payment option on your PrestaShop checkout page.
4 |
5 | ##### Note: As of PrestaShop v1.6, Simplify Commerce is pre-bundled with PrestaShop's core installation. Please head over to this repository for the latest & greatest on Simplify Commerce module source code - https://github.com/PrestaShop/simplifycommerce #####
6 |
7 | ## Installation
8 | 1. If you haven't done so already, download a release and install the zip file through the PrestaShop admin panel and enable it.
9 |
10 | 2. Configure the module by adding your API keys on the settings page (Click the 'Configure' link on the module)
11 |
12 | Optionally:
13 |
14 | 1. Unzip the downloaded source zip file and build your own module zip file by executing an 'ant' command within the root directory.
15 |
16 | 2. You can install the newly built module (located in the 'dist' folder) as before.
17 |
18 | You can manage your Simplify account (view deposits, perform refunds etc.) using the Simplify dashboard at https://www.simplify.com/commerce/.
19 |
20 | ## License
21 | This software is Open Source, released under the BSD 3-Clause license. See licence.txt for more info.
22 |
--------------------------------------------------------------------------------
/licence.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, MasterCard International Incorporated All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 |
5 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the MasterCard International Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/src/lib/index.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/css/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/img/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/js/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/lib/Simplify/index.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/views/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/views/templates/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/views/templates/hook/index.php:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/src/validation.php:
--------------------------------------------------------------------------------
1 | processPayment();
41 |
--------------------------------------------------------------------------------
/src/lib/Simplify/ResourceList.php:
--------------------------------------------------------------------------------
1 | () methods.
34 | */
35 | class SimplifyResourceList {
36 |
37 | /**
38 | * @var array $list the list of domain objects.
39 | */
40 | public $list = array();
41 |
42 | /**
43 | * @var int $total the total number of object available.
44 | */
45 | public $total = 0;
46 | }
--------------------------------------------------------------------------------
/src/lib/Simplify/Constants.php:
--------------------------------------------------------------------------------
1 |
59 |
--------------------------------------------------------------------------------
/src/views/templates/hook/order-confirmation.tpl:
--------------------------------------------------------------------------------
1 | {*
2 | * Simplify Commerce module to start accepting payments now. It's that simple.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright notice, this list of
7 | * conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright notice, this list of
9 | * conditions and the following disclaimer in the documentation and/or other materials
10 | * provided with the distribution.
11 | * Neither the name of the MasterCard International Incorporated nor the names of its
12 | * contributors may be used to endorse or promote products derived from this software
13 | * without specific prior written permission.
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
17 | * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 | * SUCH DAMAGE.
24 | *
25 | * @author MasterCard (support@simplify.com)
26 | * @version Release: 1.0.2
27 | * @copyright 2014, MasterCard International Incorporated. All rights reserved.
28 | * @license See licence.txt
29 | *}
30 | {if $simplify_order.valid == 1}
31 |
{l s='Congratulations, your payment has been approved and your order has been saved under the reference' mod='simplifycommerce'} {$simplify_order.reference|escape:html:'UTF-8'}.
32 | {else}
33 |
{l s='Sorry, unfortunately an error occured during the transaction.' mod='simplifycommerce'}
34 | {l s='Please double-check your credit card details and try again or feel free to contact us to resolve this issue.' mod='simplifycommerce'}
Amount of the payment (minor units). Example: 1000 = 10.00 required
37 | *
card.addressCity
City of the cardholder.
38 | *
card.addressCountry
Country code (ISO-3166-1-alpha-2 code) of residence of the cardholder.
39 | *
card.addressLine1
Address of the cardholder.
40 | *
card.addressLine2
Address of the cardholder if needed.
41 | *
card.addressState
State code (USPS code) of residence of the cardholder.
42 | *
card.addressZip
Postal code of the cardholder.
43 | *
card.cvc
CVC security code of the card. This is the code on the back of the card. Example: 123
44 | *
card.expMonth
Expiration month of the card. Format is MM. Example: January = 01 required
45 | *
card.expYear
Expiration year of the card. Format is YY. Example: 2013 = 13 required
46 | *
card.name
Name as it appears on the card.
47 | *
card.number
Card number as it appears on the card. required
48 | *
currency
Currency code (ISO-4217) for the transaction. Must match the currency associated with your account.
49 | * required default:USD
50 | *
customer
ID of customer. If specified, card on file of customer will be used.
51 | *
description
Custom naming of payment for external systems to use.
52 | *
reference
Custom reference field to be used with outside systems.
53 | *
token
If specified, card associated with card token will be used.
54 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
55 | * Simplify::private_key are used. For backwards compatibility the public and
56 | * private keys may be passed instead of the authentication object.
57 | * @return Payment a Payment object.
58 | */
59 | public static function createPayment($hash, $authentication = null)
60 | {
61 | $args = func_get_args();
62 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
63 |
64 | $instance = new SimplifyPayment();
65 | $instance->setAll($hash);
66 |
67 | $object = SimplifyPaymentsApi::createObject($instance, $authentication);
68 | return $object;
69 | }
70 |
71 |
72 |
73 | /**
74 | * Retrieve SimplifyPayment objects.
75 | * @param array criteria a map of parameters; valid keys are:
76 | *
filter
Filters to apply to the list.
77 | *
max
Allows up to a max of 50 list items to return. default:20
78 | *
offset
Used in paging of the list. This is the start offset of the page. default:0
79 | *
sorting
Allows for ascending or descending sorting of the list. The value maps properties to the sort direction
80 | * (either asc for ascending or desc for descending). Sortable properties are: dateCreated amount
81 | * id description paymentDate.
82 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
83 | * Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
84 | * @return ResourceList a ResourceList object that holds the list of Payment objects and the total
85 | * number of Payment objects available for the given criteria.
86 | * @see ResourceList
87 | */
88 | public static function listPayment($criteria = null, $authentication = null)
89 | {
90 | $args = func_get_args();
91 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
92 |
93 | $val = new SimplifyPayment();
94 | $list = SimplifyPaymentsApi::listObject($val, $criteria, $authentication);
95 |
96 | return $list;
97 | }
98 |
99 |
100 | /**
101 | * Retrieve a SimplifyPayment object from the API
102 | *
103 | * @param string id the id of the Payment object to retrieve
104 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
105 | * Simplify::private_key are used. For backwards compatibility the public and
106 | * private keys may be passed instead of the authentication object.
107 | * @return Payment a Payment object
108 | */
109 | public static function findPayment($id, $authentication = null)
110 | {
111 | $args = func_get_args();
112 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
113 |
114 | $val = new SimplifyPayment();
115 | $val->id = $id;
116 |
117 | $obj = SimplifyPaymentsApi::findObject($val, $authentication);
118 |
119 | return $obj;
120 | }
121 |
122 | /**
123 | * @ignore
124 | */
125 | public function getClazz()
126 | {
127 | return 'Payment';
128 | }
129 | }
--------------------------------------------------------------------------------
/src/lib/Simplify/Exceptions.php:
--------------------------------------------------------------------------------
1 | status = $status;
51 | $this->error_code = null;
52 | $this->reference = null;
53 |
54 | if ($error_data != null)
55 | {
56 | $this->reference = $error_data['reference'];
57 | $this->error_data = $error_data;
58 |
59 | $error = $error_data['error'];
60 | if ($error != null)
61 | {
62 | $m = $error['message'];
63 | if ($m != null)
64 | $this->message = $m;
65 |
66 | $this->error_code = $error['code'];
67 | }
68 | }
69 | }
70 |
71 | /**
72 | * Returns a map of all error data returned by the API.
73 | * @return array a map containing API error data.
74 | */
75 | public function getErrorData()
76 | {
77 | return $this->error_data;
78 | }
79 |
80 | /**
81 | * Returns the HTTP status for the request.
82 | * @return string HTTP status code (or null if there is no status).
83 | */
84 | public function getStatus()
85 | {
86 | return $this->status;
87 | }
88 |
89 | /**
90 | * Returns unique reference for the API error.
91 | * @return string a reference (or null if there is no reference).
92 | */
93 | public function getReference()
94 | {
95 | return $this->reference;
96 | }
97 |
98 | /**
99 | * Returns an code for the API error.
100 | * @return string the error code.
101 | */
102 | public function getErrorCode()
103 | {
104 | return $this->error_code;
105 | }
106 |
107 | /**
108 | * Returns a description of the error.
109 | * @return string Description of the error.
110 | */
111 | public function describe()
112 | {
113 | return get_class($this).': \''
114 | .$this->getMessage().'\' (status: '
115 | .$this->getStatus().', error code: '
116 | .$this->getErrorCode().', reference: '
117 | .$this->getReference().')';
118 | }
119 |
120 | }
121 |
122 |
123 | /**
124 | * Exception raised when there are communication problems contacting the API.
125 | */
126 | class SimplifyApiConnectionException extends SimplifyApiException {
127 |
128 | }
129 |
130 | /**
131 | * Exception raised where there are problems authenticating a request.
132 | */
133 | class SimplifyAuthenticationException extends SimplifyApiException {
134 |
135 | }
136 |
137 | /**
138 | * Exception raised when the API request contains errors.
139 | */
140 | class SimplifyBadRequestException extends SimplifyApiException {
141 |
142 | protected $field_errors;
143 |
144 | /**
145 | * @ignore
146 | */
147 | public function __construct($message, $status = null, $error_data = null)
148 | {
149 | parent::__construct($message, $status, $error_data);
150 |
151 | $field_errors = array();
152 |
153 | if ($error_data != null)
154 | {
155 | $error = $error_data['error'];
156 | if ($error != null)
157 | {
158 | $field_errors = $error['fieldErrors'];
159 | if ($field_errors != null)
160 | {
161 | $this->field_errors = array();
162 | foreach ($field_errors as $field_error)
163 | array_push($this->field_errors, new SimplifyFieldError($field_error));
164 | }
165 | }
166 | }
167 | }
168 |
169 | /**
170 | * Returns a boolean indicating whether there are any field errors.
171 | * @return boolean true if there are field errors; false otherwise.
172 | */
173 | public function hasFieldErrors()
174 | {
175 | return count($this->field_errors) > 0;
176 | }
177 |
178 | /**
179 | * Returns a list containing all field errors.
180 | * @return array list of field errors.
181 | */
182 | public function getFieldErrors()
183 | {
184 | return $this->field_errors;
185 | }
186 |
187 | /**
188 | * Returns a description of the error.
189 | * @return string description of the error.
190 | */
191 | public function describe()
192 | {
193 | $s = parent::describe();
194 | foreach ($this->getFieldErrors() as $field_error)
195 | $s = $s.'\n'.(string)$field_error;
196 |
197 | return $s.'\n';
198 | }
199 |
200 | }
201 |
202 | /**
203 | * Represents a single error in a field of a request sent to the API.
204 | */
205 | class SimplifyFieldError {
206 |
207 | protected $field;
208 | protected $code;
209 | protected $message;
210 |
211 | /**
212 | * @ignore
213 | */
214 | public function __construct($error_data)
215 | {
216 | $this->field = $error_data['field'];
217 | $this->code = $error_data['code'];
218 | $this->message = $error_data['message'];
219 | }
220 |
221 | /**
222 | * Returns the name of the field with the error.
223 | * @return string the field name.
224 | */
225 | public function getFieldName()
226 | {
227 | return $this->field;
228 | }
229 |
230 | /**
231 | * Returns the code for the error.
232 | * @return string the error code.
233 | */
234 | public function getErrorCode()
235 | {
236 | return $this->code;
237 | }
238 |
239 | /**
240 | * Returns a description of the error.
241 | * @return string description of the error.
242 | */
243 | public function getMessage()
244 | {
245 | return $this->message;
246 | }
247 |
248 | public function __toString()
249 | {
250 | return 'Field error: '.$this->getFieldName().'\''.$this->getMessage().'\' ('.$this->getErrorCode().')';
251 | }
252 |
253 | }
254 |
255 | /**
256 | * Exception when a requested object cannot be found.
257 | */
258 | class SimplifyObjectNotFoundException extends SimplifyApiException {
259 |
260 | }
261 |
262 | /**
263 | * Exception when a request was not allowed.
264 | */
265 | class SimplifyNotAllowedException extends SimplifyApiException {
266 |
267 | }
268 |
269 | /**
270 | * Exception when there was a system error processing a request.
271 | */
272 | class SimplifySystemException extends SimplifyApiException {
273 |
274 | }
275 |
--------------------------------------------------------------------------------
/src/views/templates/hook/payment.tpl:
--------------------------------------------------------------------------------
1 | {*
2 | * Simplify Commerce module to start accepting payments now. It's that simple.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright notice, this list of
7 | * conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright notice, this list of
9 | * conditions and the following disclaimer in the documentation and/or other materials
10 | * provided with the distribution.
11 | * Neither the name of the MasterCard International Incorporated nor the names of its
12 | * contributors may be used to endorse or promote products derived from this software
13 | * without specific prior written permission.
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
17 | * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 | * SUCH DAMAGE.
24 | *
25 | * @author MasterCard (support@simplify.com)
26 | * @version Release: 1.0.2
27 | * @copyright 2014, MasterCard International Incorporated. All rights reserved.
28 | * @license See licence.txt
29 | *}
30 |
34 |
35 |
36 |
Pay by Credit Card
37 |
38 |
39 | ( TEST PAYMENT )
40 | Payment Form not configured correctly. Please contact support.
41 |
42 |
43 |
44 |
45 | Your payment is being processed...
46 |
47 |
48 |
139 |
140 |
--------------------------------------------------------------------------------
/src/js/simplify.form.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014, MasterCard International Incorporated
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification, are
6 | * permitted provided that the following conditions are met:
7 | *
8 | * Redistributions of source code must retain the above copyright notice, this list of
9 | * conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of
11 | * conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | * Neither the name of the MasterCard International Incorporated nor the names of its
14 | * contributors may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 | * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 | * SUCH DAMAGE.
26 | */
27 |
28 | /**
29 | * JQuery validations
30 | */
31 | (function() {
32 |
33 | isNumeric = function(num) {
34 | return /[\d\s]/.test(num)
35 | };
36 |
37 | isTextSelected = function(input) {
38 | if (typeof input.prop('selectionStart') == "number") {
39 | return input.prop('selectionStart') != input.prop('selectionEnd');
40 | } else if (typeof document.selection != "undefined") {
41 | input.focus();
42 | return document.selection.createRange().text == input.val();
43 | }
44 | };
45 |
46 | cardType = function(num) {
47 |
48 | var MASTERCARD = '51,52,53,54,55,';
49 | var VISA = '4';
50 | var AMEX = '34,37,';
51 | var DISCOVER = '60,62,64,65,';
52 |
53 | if (!num) return null;
54 |
55 | if (num.substring(0, 1) === VISA) {
56 | return 'visa';
57 | }
58 | var prefix = num.substring(0, 2) + ','
59 | if (prefix.length != 3) return null;
60 |
61 | if (MASTERCARD.indexOf(prefix) != -1) {
62 | return 'mastercard';
63 | }
64 | if (AMEX.indexOf(prefix) != -1) {
65 | return 'amex';
66 | }
67 | if (DISCOVER.indexOf(prefix) != -1) {
68 | return 'discover';
69 | }
70 | return null;
71 | };
72 |
73 | restrictNumeric = function(e) {
74 |
75 | var keyCode = e.which
76 | if (keyCode === 32) {
77 | return false;
78 | }
79 | // allow some special characters, backspace etc
80 | if (keyCode < 33) {
81 | return true;
82 | }
83 |
84 | var keyChar = String.fromCharCode(keyCode);
85 | return isNumeric(keyChar);
86 | };
87 |
88 | maxlength = function(e) {
89 |
90 | var input = $(this);
91 |
92 | if (isTextSelected(input)) return;
93 |
94 | var type = input.cardType();
95 | var keyChar = String.fromCharCode(e.which);
96 |
97 | if (!isNumeric(keyChar)) {
98 | return;
99 | }
100 |
101 | var value = input.val() + keyChar;
102 | value = value.replace(/\D/g, '');
103 |
104 | if (type == 'amex') {
105 | return value.length <= 15;
106 | } else {
107 | return value.length <= 16;
108 | }
109 | };
110 |
111 | formatCardInput = function(e) {
112 |
113 | var input = $(this);
114 |
115 | if (isTextSelected(input)) return;
116 |
117 | var type = input.cardType();
118 | var value = input.val();
119 | var keyChar = String.fromCharCode(e.which);
120 |
121 | if (!isNumeric(keyChar)) {
122 | return;
123 | }
124 |
125 | var maxlength = 16;
126 | var pattern = /(?:^|\s)(\d{4})$/;
127 |
128 | if (type === 'amex') {
129 | maxlength = 15;
130 | pattern = /^(\d{4}|\d{4}\s\d{6})$/;
131 | }
132 |
133 | var length = (value.replace(/\D/g, '') + keyChar).length;
134 | if (length >= maxlength) {
135 | return;
136 | }
137 |
138 | if (pattern.test(value)) {
139 | e.preventDefault();
140 | return input.val(value + ' ' + keyChar);
141 | } else if (pattern.test(value + keyChar)) {
142 | e.preventDefault();
143 | return input.val(value + keyChar + ' ');
144 | }
145 | };
146 |
147 | formatCardBackspace = function(e) {
148 |
149 | var BACK_SPACE = 8;
150 |
151 | var input = $(this);
152 | var value = input.val();
153 |
154 | if (isTextSelected(input)) return;
155 |
156 | if (e.which === BACK_SPACE && /\s\d?$/.test(value)) {
157 | e.preventDefault();
158 | return input.val(value.replace(/\s\d?$/, ''));
159 | }
160 | };
161 |
162 | formatExpiryInput = function(e) {
163 |
164 | var input = $(this);
165 | var value = $(this).val();
166 |
167 | if (isTextSelected(input)) return;
168 |
169 | var keyChar = String.fromCharCode(e.which);
170 | var slash = keyChar == '/';
171 |
172 | if (value.replace(/\D/g, '').length >= 4 && e.which != 8 && e.which != 0) {
173 | return false;
174 | }
175 |
176 | if (!isNumeric(keyChar) && !slash) {
177 | return;
178 | }
179 |
180 | if (value.length != 1 && slash) {
181 | return;
182 | }
183 |
184 | if (value.length == 1 && slash) {
185 | input.val('0' + value + '/');
186 | } else if (value.length == 1 && !slash) {
187 | input.val(value + keyChar + '/');
188 | } else {
189 | input.val(value + keyChar);
190 | }
191 |
192 | e.preventDefault();
193 | };
194 |
195 | expiryDate = function(expiry) {
196 |
197 | if (expiry) {
198 |
199 | var dates = expiry.split('/')
200 | return {
201 | 'month': dates[0],
202 | 'year': dates[1]
203 | }
204 | }
205 | return {
206 | 'month': null,
207 | 'year': null
208 | }
209 | };
210 |
211 | /**
212 | * Restrict the entry of a non numeric in an input field
213 | */
214 | $.fn.restrictNumeric = function() {
215 | return this.keypress(restrictNumeric);
216 | };
217 |
218 | $.fn.cardType = function() {
219 | return cardType(this.val());
220 | };
221 |
222 | /**
223 | * Formats the entry of a card number into groups of four e.g. **** **** **** ****
224 | * @returns {*}
225 | */
226 | $.fn.formatCardNumber = function() {
227 | this.restrictNumeric();
228 | this.keypress(maxlength);
229 | this.keypress(formatCardInput);
230 | this.keydown(formatCardBackspace);
231 | return
232 | };
233 |
234 | /**
235 | * Formats an expiry date into dd/dd
236 | */
237 | $.fn.formatExpiryNumber = function() {
238 | this.restrictNumeric();
239 | this.keypress(formatExpiryInput);
240 | return
241 | };
242 |
243 | /**
244 | * Return an object with the expiry month and year
245 | *
246 | * {'month': '01', 'year': '12'}
247 | *
248 | * @returns {*}
249 | */
250 | $.fn.expiryDate = function() {
251 | return expiryDate(this.val());
252 | };
253 |
254 | }).call(this);
--------------------------------------------------------------------------------
/src/js/simplify.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2014, MasterCard International Incorporated
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification, are
6 | * permitted provided that the following conditions are met:
7 | *
8 | * Redistributions of source code must retain the above copyright notice, this list of
9 | * conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of
11 | * conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | * Neither the name of the MasterCard International Incorporated nor the names of its
14 | * contributors may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 | * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 | * SUCH DAMAGE.
26 | */
27 |
28 | /**
29 | * Function to handle the form submission
30 | */
31 | $(document).ready(function() {
32 |
33 | if ($('.simplify-payment-errors').text().length > 0) {
34 | $('.simplify-payment-errors').show();
35 | }
36 |
37 | // Check that the Simplify API Keys are set
38 | if (simplifyPublicKey.length == 0) {
39 | $('#simplify-no-keys-msg').show();
40 | $('.simplify-submit-button').attr('disabled', 'disabled');
41 | return;
42 | }
43 |
44 | // Display warning message that this is a test payment as test api keys are being used.
45 | if (simplifyPublicKey.indexOf('sbpb_') !== -1) {
46 | $('#simplify-test-mode-msg').show();
47 | }
48 |
49 | $(".simplify-card-cvc").restrictNumeric();
50 | $('.simplify-card-number').formatCardNumber();
51 |
52 | /**
53 | * Function to watch the form of payment being used and
54 | * to show and hide the relevant form components.
55 | */
56 | $("input[name='cc-type']").change(function() {
57 | var ccDetails = $("#simplify-cc-details");
58 | $('.card-type-container').removeClass('selected');
59 | $(this).parents('.card-type-container').addClass('selected');
60 |
61 | if ($("input[name='cc-type']:checked").val() == 'new') {
62 | if ($("#cc-deletion-msg").is(':visible')) {
63 | showSaveCardDetailsLabel(true);
64 | } else {
65 | showSaveCardDetailsLabel(false);
66 | }
67 |
68 | ccDetails.fadeIn();
69 | } else {
70 | ccDetails.fadeOut();
71 | }
72 | });
73 |
74 | /**
75 | * Function to show the confirm deletion container when the
76 | * trash icon is clicked.
77 | */
78 | $('#trash-icon').click(function() {
79 | $('#cc-confirm-deletion').slideDown();
80 | });
81 |
82 | /**
83 | * Function to hide the credit card details option,
84 | * select the 'new card' option and provide the user
85 | * a control to undo the deletion.
86 | */
87 | $('#confirm-cc-deletion').click(function() {
88 | $("#old-card-container").fadeOut('fast', function() {
89 | $("#new-card-container input[name='cc-type']").click();
90 | $("#cc-deletion-msg").slideDown(function() {
91 | showSaveCardDetailsLabel(true);
92 | });
93 | });
94 |
95 | $('#simplify-payment-form').append('');
96 | });
97 |
98 | /**
99 | * Function to hide the confirm deletion container.
100 | */
101 | $('#cancel-cc-deletion').click(function() {
102 | $('#cc-confirm-deletion').slideUp();
103 | });
104 |
105 | /**
106 | * Function to restore the save card details
107 | * form option.
108 | */
109 | $('#cc-undo-deletion-lnk').click(function() {
110 | $("#cc-deletion-msg").hide();
111 | $('#cc-confirm-deletion').hide();
112 | $("#old-card-container").fadeIn('fast');
113 | $('#deleteCustomerCard').remove();
114 | showSaveCardDetailsLabel(false);
115 | });
116 |
117 | /**
118 | * Function to handle the form submission and either
119 | * generate a new card token for new cards or
120 | * charge an existing user's card.
121 | */
122 | $('#simplify-payment-form').submit(function() {
123 |
124 | $('#simplify-ajax-loader').show();
125 | $('.simplify-payment-errors').hide();
126 | $('.simplify-submit-button').attr('disabled', 'disabled'); /* Disable the submit button to prevent repeated clicks */
127 |
128 | // Fetch a card token for new card details otherwise submit form with existing card details
129 | if ($("#simplify-cc-details").is(':visible')) {
130 | if (simplifyPublicKey.length == 0) {
131 | return false;
132 | }
133 |
134 | SimplifyCommerce.generateToken({
135 | key: simplifyPublicKey,
136 | card: {
137 | number: $(".simplify-card-number").val().trim().replace(/\s+/g, ''),
138 | cvc: $(".simplify-card-cvc").val(),
139 | expMonth: $("#simplify-cc-details select[name='Date_Month']").val(),
140 | expYear: $("#simplify-cc-details select[name='Date_Year']").val().substring(2),
141 | name: simplifyFirstname + ' ' + simplifyLastname,
142 | addressCity: simplifyCity,
143 | addressLine1: simplifyAddress1,
144 | addressLine2: simplifyAddress2,
145 | addressState: simplifyState,
146 | addressZip: simplifyPostcode
147 | }
148 | }, simplifyResponseHandler);
149 |
150 | return false; /* Prevent the form from submitting with the default action */
151 | } else {
152 | $('#simplify-payment-form')
153 | .append('')
154 | .get(0).submit();
155 | }
156 | });
157 |
158 | });
159 |
160 | /**
161 | * Function to retrieve a cardholder detail or empty string if it doesn't exist.
162 | */
163 | function getCardHolderDetail(detail) {
164 | return (typeof cardholderDetails[detail] !== 'undefined') ? cardholderDetails[detail] : '';
165 | }
166 |
167 | /**
168 | * Function to toggle the visibility of the the 'save card details' label
169 | */
170 | function showSaveCardDetailsLabel(isSaveCardeDetailsLabelVisible) {
171 | var $saveCustomerLabel = $('#saveCustomerLabel'),
172 | $updateCustomerLabel = $('#updateCustomerLabel');
173 |
174 | if (isSaveCardeDetailsLabelVisible) {
175 | $saveCustomerLabel.show();
176 | $updateCustomerLabel.hide();
177 | } else {
178 | $updateCustomerLabel.show();
179 | $saveCustomerLabel.hide();
180 | }
181 | }
182 |
183 | /**
184 | * Function to handle the response from Simplify Commerce's tokenization call.
185 | */
186 | function simplifyResponseHandler(data) {
187 | if (data.error) {
188 | var errorMessages = {
189 | 'card.number': 'The credit card number you entered is invalid.',
190 | 'card.expYear': 'The expiry year on the credit card is invalid.'
191 | };
192 |
193 | // Show any validation errors
194 | if (data.error.code == "validation") {
195 | var fieldErrors = data.error.fieldErrors,
196 | fieldErrorsLength = fieldErrors.length,
197 | errorList = "";
198 |
199 | for (var i = 0; i < fieldErrorsLength; i++) {
200 | errorList += "
Country code (ISO-3166-1-alpha-2 code) of residence of the cardholder.
38 | * required
39 | *
card.addressLine1
Address of the cardholder required
40 | *
card.addressLine2
Address of the cardholder if needed. required
41 | *
card.addressState
State code (USPS code) of residence of the cardholder. required
42 | *
card.addressZip
Postal code of the cardholder. required
43 | *
card.cvc
CVC security code of the card. This is the code on the back of the card. Example: 123
44 | * required
45 | *
card.expMonth
Expiration month of the card. Format is MM. Example: January = 01 required
46 | *
card.expYear
Expiration year of the card. Format is YY. Example: 2013 = 13 required
47 | *
card.id
ID of card. Unused during customer create.
48 | *
card.name
Name as appears on the card. required
49 | *
card.number
Card number as it appears on the card.
50 | *
email
Email address of the customer required
51 | *
name
Customer name required
52 | *
reference
Reference field for external applications use.
53 | *
subscriptions.amount
Amount of payment in minor units. Example: 1000 = 10.00
54 | *
subscriptions.coupon
Coupon associated with the subscription for the customer.
55 | *
subscriptions.currency
Currency code (ISO-4217). Must match the currency associated with your
56 | * account. default:USD
57 | *
subscriptions.customer
The customer ID to create the subscription for. Do not supply this
58 | * when creating a customer.
59 | *
subscriptions.frequency
Frequency of payment for the plan. Example: Monthly
60 | *
subscriptions.name
Name describing subscription
61 | *
subscriptions.plan
The plan ID that the subscription should be created from.
62 | *
subscriptions.quantity
Quantity of the plan for the subscription.
63 | *
token
If specified, card associated with card token will be used
64 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
65 | * Simplify::private_key are used. For backwards compatibility the public and
66 | * private keys may be passed instead of the authentication object.
67 | * @return Customer a Customer object.
68 | */
69 | public static function createCustomer($hash, $authentication = null)
70 | {
71 | $args = func_get_args();
72 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
73 |
74 | $instance = new SimplifyCustomer();
75 | $instance->setAll($hash);
76 |
77 | $object = SimplifyPaymentsApi::createObject($instance, $authentication);
78 | return $object;
79 | }
80 |
81 | /**
82 | * Deletes an SimplifyCustomer object.
83 | *
84 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key
85 | * and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed
86 | * instead of the authentication object.
87 | */
88 | public function deleteCustomer($authentication = null)
89 | {
90 | $args = func_get_args();
91 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 1);
92 |
93 | SimplifyPaymentsApi::deleteObject($this, $authentication);
94 | $this->properties = null;
95 | return true;
96 | }
97 |
98 |
99 | /**
100 | * Retrieve SimplifyCustomer objects.
101 | * @param array criteria a map of parameters; valid keys are:
102 | *
filter
Filters to apply to the list.
103 | *
max
Allows up to a max of 50 list items to return. default:20
104 | *
offset
Used in paging of the list. This is the start offset of the page. default:0
105 | *
sorting
Allows for ascending or descending sorting of the list. The value maps properties to the sort direction
106 | * (either asc for ascending or desc for descending). Sortable properties are: dateCreated id name
107 | * email reference.
108 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
109 | * Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
110 | * @return ResourceList a ResourceList object that holds the list of Customer objects and the total
111 | * number of Customer objects available for the given criteria.
112 | * @see ResourceList
113 | */
114 | public static function listCustomer($criteria = null, $authentication = null)
115 | {
116 | $args = func_get_args();
117 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
118 |
119 | $val = new SimplifyCustomer();
120 | $list = SimplifyPaymentsApi::listObject($val, $criteria, $authentication);
121 |
122 | return $list;
123 | }
124 |
125 |
126 | /**
127 | * Retrieve a SimplifyCustomer object from the API
128 | *
129 | * @param string id the id of the Customer object to retrieve
130 | * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and
131 | * Simplify::private_key are used. For backwards compatibility the public and
132 | * private keys may be passed instead of the authentication object.
133 | * @return Customer a Customer object
134 | */
135 | public static function findCustomer($id, $authentication = null)
136 | {
137 | $args = func_get_args();
138 | $authentication = SimplifyPaymentsApi::buildAuthenticationObject($authentication, $args, 2);
139 |
140 | $val = new SimplifyCustomer();
141 | $val->id = $id;
142 |
143 | $obj = SimplifyPaymentsApi::findObject($val, $authentication);
144 |
145 | return $obj;
146 | }
147 |
148 |
149 | /**
150 | * Updates an SimplifyCustomer object.
151 | *
152 | * The properties that can be updated:
153 | *
Click the "Sign up for free" button and become a Simplify merchant for free.
646 |
647 |
648 |
649 |
650 |
651 |
Simple pricing
652 |
No setup fees. No monthly fees. No minimum.
653 |
654 |
655 |
656 |
657 |
658 |
Two-day funding
659 |
Deposits are made into your account in two business days for most transactions.
660 |
661 |
662 |
663 |
664 |
665 |
666 |
Technical Checks
667 |
'.
668 | $this->l('Good news! Everything looks to be in order. Start accepting credit card payments now.') :
669 | 'warn">'.$this->l('Unfortunately, at least one issue is preventing you from using Simplify Commerce.
670 | Please fix the issue and reload this page.')).'