├── LICENSE.md ├── README.md ├── api ├── blesta_api.php └── blesta_response.php └── components └── gateways ├── merchant └── merchant_demo_cc │ ├── language │ └── en_us │ │ └── merchant_demo_cc.php │ ├── merchant_demo_cc.php │ └── views │ └── default │ ├── images │ └── logo.png │ └── settings.pdt └── nonmerchant └── nonmerchant_demo ├── language └── en_us │ └── nonmerchant_demo.php ├── nonmerchant_demo.php └── views └── default ├── images └── logo.png ├── process.pdt └── settings.pdt /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License # 2 | 3 | Copyright (c) 2010-2013 [Phillips Data, Inc.](https://github.com/phillipsdata) 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blesta SDK # 2 | 3 | This development kit includes the following: 4 | 5 | * An API processor to make interfacing with the Blesta API super simple 6 | * Sample Merchant and Non-merchant Gateway implementations 7 | 8 | ## Requirements ## 9 | 10 | * PHP 5.2.0 or greater 11 | * Blesta 3.0.0 or greater 12 | 13 | ## Using the API ## 14 | 15 | Documentation on the API can be found in the [API](http://docs.blesta.com/display/dev/API) section of the [Developer Manual](http://docs.blesta.com/display/dev/) 16 | 17 | ```php 18 | get("users", "get", array('user_id' => 1)); 28 | 29 | print_r($response->response()); 30 | print_r($response->errors()); 31 | 32 | ?> 33 | ``` 34 | 35 | Plugin models are accessible as well: 36 | 37 | ```php 38 | post("support_manager.support_manager_tickets", "close", array('ticket_id' => 1)); 48 | 49 | print_r($response->response()); 50 | print_r($response->errors()); 51 | 52 | ?> 53 | ``` 54 | 55 | ## Working with Gateways ## 56 | 57 | Documentation on gateways can be found in the [Payment Gateways](http://docs.blesta.com/display/dev/Payment+Gateways) section of the [Developer Manual](http://docs.blesta.com/display/dev/) 58 | 59 | Included in this SKD are two example gateways: 60 | 61 | * Merchant Credit Card Gateway _/components/gateways/merchant/merchant_demo_cc/_ 62 | * Non-merchant Gateway _/components/gateways/nonmerchant/nonmerchant_demo/_ -------------------------------------------------------------------------------- /api/blesta_api.php: -------------------------------------------------------------------------------- 1 | url = $url; 39 | $this->user = $user; 40 | $this->key = $key; 41 | } 42 | 43 | /** 44 | * Submit an API request via GET 45 | * 46 | * @param string $model The model to request (e.g. users) 47 | * @param string $method The method to request (e.g. add) 48 | * @param array $args An array of arguments to pass to the method 49 | * @return BlestaResponse The response object 50 | */ 51 | public function get($model, $method, array $args = array()) { 52 | return $this->submit($model, $method, $args, "GET"); 53 | } 54 | 55 | /** 56 | * Submit an API request via POST 57 | * 58 | * @param string $model The model to request (e.g. users) 59 | * @param string $method The method to request (e.g. add) 60 | * @param array $args An array of arguments to pass to the method 61 | * @return BlestaResponse The response object 62 | */ 63 | public function post($model, $method, array $args = array()) { 64 | return $this->submit($model, $method, $args, "POST"); 65 | } 66 | 67 | /** 68 | * Submit an API request via PUT 69 | * 70 | * @param string $model The model to request (e.g. users) 71 | * @param string $method The method to request (e.g. add) 72 | * @param array $args An array of arguments to pass to the method 73 | * @return BlestaResponse The response object 74 | */ 75 | public function put($model, $method, array $args = array()) { 76 | return $this->submit($model, $method, $args, "PUT"); 77 | } 78 | 79 | /** 80 | * Submit an API request via DELETE 81 | * 82 | * @param string $model The model to request (e.g. users) 83 | * @param string $method The method to request (e.g. add) 84 | * @param array $args An array of arguments to pass to the method 85 | * @return BlestaResponse The response object 86 | */ 87 | public function delete($model, $method, array $args = array()) { 88 | return $this->submit($model, $method, $args, "DELETE"); 89 | } 90 | 91 | /** 92 | * Submits a request to the API 93 | * 94 | * @param string $uri The URI to submit to 95 | * @param array $args An array of key/value pair arguments to submit to the given API command 96 | * @return BlestaResponse The response object 97 | */ 98 | private function submit($model, $method, array $args = array(), $action = "POST") { 99 | 100 | $url = $this->url . $model . "/" . $method . "." . self::$format; 101 | 102 | $this->last_request = array( 103 | 'url' => $url, 104 | 'args' => $args 105 | ); 106 | 107 | if ($action == "GET") { 108 | $url .= "?" . http_build_query($args); 109 | $args = null; 110 | } 111 | 112 | $ch = curl_init(); 113 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 114 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $action); 115 | curl_setopt($ch, CURLOPT_URL, $url); 116 | if ($args) { 117 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args)); 118 | } 119 | 120 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 121 | curl_setopt($ch, CURLOPT_USERPWD, $this->user . ":" . $this->key); 122 | //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 123 | //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 124 | $response = curl_exec($ch); 125 | $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 126 | curl_close($ch); 127 | 128 | return new BlestaResponse($response, $response_code); 129 | } 130 | 131 | /** 132 | * Returns the details of the last request made 133 | * 134 | * @return array An array containg: 135 | * - url The URL of the last request 136 | * - args The paramters passed to the URL 137 | */ 138 | public function lastRequest() { 139 | return $this->last_request; 140 | } 141 | } 142 | ?> -------------------------------------------------------------------------------- /api/blesta_response.php: -------------------------------------------------------------------------------- 1 | raw = $response; 27 | $this->response_code = $response_code; 28 | } 29 | 30 | /** 31 | * Returns the response from the request 32 | * 33 | * @return mixed A stdClass object representing the response returned from the request, null if no response returned 34 | */ 35 | public function response() { 36 | $response = $this->formatResponse(); 37 | if (isset($response->response)) 38 | return $response->response; 39 | return null; 40 | } 41 | 42 | /** 43 | * Returns the HTTP response code 44 | * 45 | * @return int The HTTP response code for the request 46 | */ 47 | public function responseCode() { 48 | return $this->response_code; 49 | } 50 | 51 | /** 52 | * Returns the raw response 53 | * 54 | * @return string The raw response 55 | */ 56 | public function raw() { 57 | return $this->raw; 58 | } 59 | 60 | /** 61 | * Returns all errors contained in the response 62 | * 63 | * @return stdClass A stdClass object representing the errors in the response, false if invalid response 64 | */ 65 | public function errors() { 66 | if ($this->response_code != 200) { 67 | $response = $this->formatResponse(); 68 | 69 | if (isset($response->errors)) 70 | return $response->errors; 71 | else { 72 | $error = new stdClass(); 73 | $error->error = $response; 74 | return $error; 75 | } 76 | } 77 | return false; 78 | } 79 | 80 | /** 81 | * Formats the raw response into a stdClass object 82 | * 83 | * @return stdClass A stdClass object representing the resposne 84 | */ 85 | private function formatResponse() { 86 | return json_decode($this->raw); 87 | } 88 | } 89 | ?> -------------------------------------------------------------------------------- /components/gateways/merchant/merchant_demo_cc/language/en_us/merchant_demo_cc.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /components/gateways/merchant/merchant_demo_cc/merchant_demo_cc.php: -------------------------------------------------------------------------------- 1 | "Phillips Data, Inc.", 'url' => "http://www.blesta.com")); 20 | /** 21 | * @var array An array of meta data for this gateway 22 | */ 23 | private $meta; 24 | 25 | /** 26 | * Construct a new merchant gateway 27 | */ 28 | public function __construct() { 29 | // Load components required by this module 30 | Loader::loadComponents($this, array("Input")); 31 | 32 | // Load the language required by this module 33 | Language::loadLang("merchant_demo_cc", null, dirname(__FILE__) . DS . "language" . DS); 34 | } 35 | 36 | /** 37 | * Returns the name of this gateway 38 | * 39 | * @return string The common name of this gateway 40 | */ 41 | public function getName() { 42 | return Language::_("MerchantDemoCc.name", true); 43 | } 44 | 45 | /** 46 | * Returns the version of this gateway 47 | * 48 | * @return string The current version of this gateway 49 | */ 50 | public function getVersion() { 51 | return self::$version; 52 | } 53 | 54 | /** 55 | * Returns the name and URL for the authors of this gateway 56 | * 57 | * @return array The name and URL of the authors of this gateway 58 | */ 59 | public function getAuthors() { 60 | return self::$authors; 61 | } 62 | 63 | /** 64 | * Return all currencies supported by this gateway 65 | * 66 | * @return array A numerically indexed array containing all currency codes (ISO 4217 format) this gateway supports 67 | */ 68 | public function getCurrencies() { 69 | return array("USD", "GBP", "EUR"); 70 | } 71 | 72 | /** 73 | * Sets the currency code to be used for all subsequent payments 74 | * 75 | * @param string $currency The ISO 4217 currency code to be used for subsequent payments 76 | */ 77 | public function setCurrency($currency) { 78 | $this->currency = $currency; 79 | } 80 | 81 | /** 82 | * Create and return the view content required to modify the settings of this gateway 83 | * 84 | * @param array $meta An array of meta (settings) data belonging to this gateway 85 | * @return string HTML content containing the fields to update the meta data for this gateway 86 | */ 87 | public function getSettings(array $meta=null) { 88 | $this->view = $this->makeView("settings", "default", str_replace(ROOTWEBDIR, "", dirname(__FILE__) . DS)); 89 | 90 | // Load the helpers required for this view 91 | Loader::loadHelpers($this, array("Form", "Html")); 92 | 93 | $this->view->set("meta", $meta); 94 | 95 | return $this->view->fetch(); 96 | } 97 | 98 | /** 99 | * Validates the given meta (settings) data to be updated for this gateway 100 | * 101 | * @param array $meta An array of meta (settings) data to be updated for this gateway 102 | * @return array The meta data to be updated in the database for this gateway, or reset into the form on failure 103 | */ 104 | public function editSettings(array $meta) { 105 | // Verify meta data is valid 106 | $rules = array( 107 | 'key'=>array( 108 | 'valid'=>array( 109 | 'rule'=>array("betweenLength", 16, 16), 110 | 'message'=>Language::_("MerchantDemoCc.!error.key.valid", true) 111 | ) 112 | ) 113 | 114 | # 115 | # TODO: Do error checking on any other fields that require it 116 | # 117 | 118 | ); 119 | 120 | $this->Input->setRules($rules); 121 | 122 | // Validate the given meta data to ensure it meets the requirements 123 | $this->Input->validates($meta); 124 | // Return the meta data, no changes required regardless of success or failure for this gateway 125 | return $meta; 126 | } 127 | 128 | /** 129 | * Returns an array of all fields to encrypt when storing in the database 130 | * 131 | * @return array An array of the field names to encrypt when storing in the database 132 | */ 133 | public function encryptableFields() { 134 | return array("key"); 135 | } 136 | 137 | /** 138 | * Sets the meta data for this particular gateway 139 | * 140 | * @param array $meta An array of meta data to set for this gateway 141 | */ 142 | public function setMeta(array $meta=null) { 143 | $this->meta = $meta; 144 | } 145 | 146 | /** 147 | * Used to determine whether this gateway can be configured for autodebiting accounts 148 | * 149 | * @return boolean True if the customer must be present (e.g. in the case of credit card customer must enter security code), false otherwise 150 | */ 151 | public function requiresCustomerPresent() { 152 | return false; 153 | } 154 | 155 | 156 | /** 157 | * Charge a credit card 158 | * 159 | * @param array $card_info An array of credit card info including: 160 | * - first_name The first name on the card 161 | * - last_name The last name on the card 162 | * - card_number The card number 163 | * - card_exp The card expiration date in yyyymm format 164 | * - card_security_code The 3 or 4 digit security code of the card (if available) 165 | * - type The credit card type 166 | * - address1 The address 1 line of the card holder 167 | * - address2 The address 2 line of the card holder 168 | * - city The city of the card holder 169 | * - state An array of state info including: 170 | * - code The 2 or 3-character state code 171 | * - name The local name of the state 172 | * - country An array of country info including: 173 | * - alpha2 The 2-character country code 174 | * - alpha3 The 3-character country code 175 | * - name The english name of the country 176 | * - alt_name The local name of the country 177 | * - zip The zip/postal code of the card holder 178 | * @param float $amount The amount to charge this card 179 | * @param array $invoice_amounts An array of invoices, each containing: 180 | * - id The ID of the invoice being processed 181 | * - amount The amount being processed for this invoice (which is included in $amount) 182 | * @return array An array of transaction data including: 183 | * - status The status of the transaction (approved, declined, void, pending, error, refunded, returned) 184 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 185 | * - transaction_id The ID returned by the remote gateway to identify this transaction 186 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 187 | */ 188 | public function processCc(array $card_info, $amount, array $invoice_amounts=null) { 189 | 190 | # 191 | # TODO: Submit the request to the remote gateway processor, log the 192 | # submission and response, then return the transaction data 193 | # 194 | 195 | return array( 196 | 'status' => "approved", 197 | 'reference_id' => null, 198 | 'transaction_id' => substr(md5(microtime()), -16) 199 | ); 200 | } 201 | 202 | /** 203 | * Authorize a credit card 204 | * 205 | * @param array $card_info An array of credit card info including: 206 | * - first_name The first name on the card 207 | * - last_name The last name on the card 208 | * - card_number The card number 209 | * - card_exp The card expiration date in yyyymm format 210 | * - card_security_code The 3 or 4 digit security code of the card (if available) 211 | * - type The credit card type 212 | * - address1 The address 1 line of the card holder 213 | * - address2 The address 2 line of the card holder 214 | * - city The city of the card holder 215 | * - state An array of state info including: 216 | * - code The 2 or 3-character state code 217 | * - name The local name of the country 218 | * - country An array of country info including: 219 | * - alpha2 The 2-character country code 220 | * - alpha3 The 3-cahracter country code 221 | * - name The english name of the country 222 | * - alt_name The local name of the country 223 | * - zip The zip/postal code of the card holder 224 | * @param float $amount The amount to charge this card 225 | * @param array $invoice_amounts An array of invoices, each containing: 226 | * - id The ID of the invoice being processed 227 | * - amount The amount being processed for this invoice (which is included in $amount) 228 | * @return array An array of transaction data including: 229 | * - status The status of the transaction (approved, declined, void, pending, error, refunded, returned) 230 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 231 | * - transaction_id The ID returned by the remote gateway to identify this transaction 232 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 233 | */ 234 | public function authorizeCc(array $card_info, $amount, array $invoice_amounts=null) { 235 | // Gateway does not support this action 236 | $this->Input->setErrors($this->getCommonError("unsupported")); 237 | } 238 | 239 | /** 240 | * Capture the funds of a previously authorized credit card 241 | * 242 | * @param string $reference_id The reference ID for the previously authorized transaction 243 | * @param string $transaction_id The transaction ID for the previously authorized transaction 244 | * @param float $amount The amount to capture on this card 245 | * @param array $invoice_amounts An array of invoices, each containing: 246 | * - id The ID of the invoice being processed 247 | * - amount The amount being processed for this invoice (which is included in $amount) 248 | * @return array An array of transaction data including: 249 | * - status The status of the transaction (approved, declined, void, pending, error, refunded, returned) 250 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 251 | * - transaction_id The ID returned by the remote gateway to identify this transaction 252 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 253 | */ 254 | public function captureCc($reference_id, $transaction_id, $amount, array $invoice_amounts=null) { 255 | // Gateway does not support this action 256 | $this->Input->setErrors($this->getCommonError("unsupported")); 257 | } 258 | 259 | /** 260 | * Void a credit card charge 261 | * 262 | * @param string $reference_id The reference ID for the previously authorized transaction 263 | * @param string $transaction_id The transaction ID for the previously authorized transaction 264 | * @return array An array of transaction data including: 265 | * - status The status of the transaction (approved, declined, void, pending, error, refunded, returned) 266 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 267 | * - transaction_id The ID returned by the remote gateway to identify this transaction 268 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 269 | */ 270 | public function voidCc($reference_id, $transaction_id) { 271 | // Gateway does not support this action 272 | $this->Input->setErrors($this->getCommonError("unsupported")); 273 | } 274 | 275 | /** 276 | * Refund a credit card charge 277 | * 278 | * @param string $reference_id The reference ID for the previously authorized transaction 279 | * @param string $transaction_id The transaction ID for the previously authorized transaction 280 | * @param float $amount The amount to refund this card 281 | * @return array An array of transaction data including: 282 | * - status The status of the transaction (approved, declined, void, pending, error, refunded, returned) 283 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 284 | * - transaction_id The ID returned by the remote gateway to identify this transaction 285 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 286 | */ 287 | public function refundCc($reference_id, $transaction_id, $amount) { 288 | // Gateway does not support this action 289 | $this->Input->setErrors($this->getCommonError("unsupported")); 290 | } 291 | } 292 | ?> -------------------------------------------------------------------------------- /components/gateways/merchant/merchant_demo_cc/views/default/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phillipsdata/blesta_sdk/052760da4d9468c2d49edf1482ec97d35c85f162/components/gateways/merchant/merchant_demo_cc/views/default/images/logo.png -------------------------------------------------------------------------------- /components/gateways/merchant/merchant_demo_cc/views/default/settings.pdt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /components/gateways/nonmerchant/nonmerchant_demo/language/en_us/nonmerchant_demo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /components/gateways/nonmerchant/nonmerchant_demo/nonmerchant_demo.php: -------------------------------------------------------------------------------- 1 | "Phillips Data, Inc.", 'url' => "http://www.blesta.com")); 20 | /** 21 | * @var array An array of meta data for this gateway 22 | */ 23 | private $meta; 24 | 25 | 26 | /** 27 | * Construct a new merchant gateway 28 | */ 29 | public function __construct() { 30 | 31 | // Load components required by this gateway 32 | Loader::loadComponents($this, array("Input")); 33 | 34 | // Load the language required by this gateway 35 | Language::loadLang("nonmerchant_demo", null, dirname(__FILE__) . DS . "language" . DS); 36 | } 37 | 38 | /** 39 | * Returns the name of this gateway 40 | * 41 | * @return string The common name of this gateway 42 | */ 43 | public function getName() { 44 | return Language::_("NonmerchantDemo.name", true); 45 | } 46 | 47 | /** 48 | * Returns the version of this gateway 49 | * 50 | * @return string The current version of this gateway 51 | */ 52 | public function getVersion() { 53 | return self::$version; 54 | } 55 | 56 | /** 57 | * Returns the name and URL for the authors of this gateway 58 | * 59 | * @return array The name and URL of the authors of this gateway 60 | */ 61 | public function getAuthors() { 62 | return self::$authors; 63 | } 64 | 65 | /** 66 | * Return all currencies supported by this gateway 67 | * 68 | * @return array A numerically indexed array containing all currency codes (ISO 4217 format) this gateway supports 69 | */ 70 | public function getCurrencies() { 71 | return array("EUR", "GBP", "USD"); 72 | } 73 | 74 | /** 75 | * Sets the currency code to be used for all subsequent payments 76 | * 77 | * @param string $currency The ISO 4217 currency code to be used for subsequent payments 78 | */ 79 | public function setCurrency($currency) { 80 | $this->currency = $currency; 81 | } 82 | 83 | /** 84 | * Create and return the view content required to modify the settings of this gateway 85 | * 86 | * @param array $meta An array of meta (settings) data belonging to this gateway 87 | * @return string HTML content containing the fields to update the meta data for this gateway 88 | */ 89 | public function getSettings(array $meta=null) { 90 | $this->view = $this->makeView("settings", "default", str_replace(ROOTWEBDIR, "", dirname(__FILE__) . DS)); 91 | 92 | // Load the helpers required for this view 93 | Loader::loadHelpers($this, array("Form", "Html")); 94 | 95 | $this->view->set("meta", $meta); 96 | 97 | return $this->view->fetch(); 98 | } 99 | 100 | /** 101 | * Validates the given meta (settings) data to be updated for this gateway 102 | * 103 | * @param array $meta An array of meta (settings) data to be updated for this gateway 104 | * @return array The meta data to be updated in the database for this gateway, or reset into the form on failure 105 | */ 106 | public function editSettings(array $meta) { 107 | // Verify meta data is valid 108 | $rules = array( 109 | 'key'=>array( 110 | 'valid'=>array( 111 | 'rule'=>array("betweenLength", 16, 16), 112 | 'message'=>Language::_("NonmerchantDemo.!error.key.valid", true) 113 | ) 114 | ) 115 | 116 | # 117 | # TODO: Do error checking on any other fields that require it 118 | # 119 | 120 | ); 121 | 122 | $this->Input->setRules($rules); 123 | 124 | // Validate the given meta data to ensure it meets the requirements 125 | $this->Input->validates($meta); 126 | // Return the meta data, no changes required regardless of success or failure for this gateway 127 | return $meta; 128 | } 129 | 130 | /** 131 | * Returns an array of all fields to encrypt when storing in the database 132 | * 133 | * @return array An array of the field names to encrypt when storing in the database 134 | */ 135 | public function encryptableFields() { 136 | 137 | # 138 | # TODO: return an array of all meta field names to store encrypted 139 | # 140 | 141 | return array("key"); 142 | } 143 | 144 | /** 145 | * Sets the meta data for this particular gateway 146 | * 147 | * @param array $meta An array of meta data to set for this gateway 148 | */ 149 | public function setMeta(array $meta=null) { 150 | $this->meta = $meta; 151 | } 152 | 153 | /** 154 | * Returns all HTML markup required to render an authorization and capture payment form 155 | * 156 | * @param array $contact_info An array of contact info including: 157 | * - id The contact ID 158 | * - client_id The ID of the client this contact belongs to 159 | * - user_id The user ID this contact belongs to (if any) 160 | * - contact_type The type of contact 161 | * - contact_type_id The ID of the contact type 162 | * - first_name The first name on the contact 163 | * - last_name The last name on the contact 164 | * - title The title of the contact 165 | * - company The company name of the contact 166 | * - address1 The address 1 line of the contact 167 | * - address2 The address 2 line of the contact 168 | * - city The city of the contact 169 | * - state An array of state info including: 170 | * - code The 2 or 3-character state code 171 | * - name The local name of the country 172 | * - country An array of country info including: 173 | * - alpha2 The 2-character country code 174 | * - alpha3 The 3-cahracter country code 175 | * - name The english name of the country 176 | * - alt_name The local name of the country 177 | * - zip The zip/postal code of the contact 178 | * @param float $amount The amount to charge this contact 179 | * @param array $invoice_amounts An array of invoices, each containing: 180 | * - id The ID of the invoice being processed 181 | * - amount The amount being processed for this invoice (which is included in $amount) 182 | * @param array $options An array of options including: 183 | * - description The Description of the charge 184 | * - return_url The URL to redirect users to after a successful payment 185 | * - recur An array of recurring info including: 186 | * - amount The amount to recur 187 | * - term The term to recur 188 | * - period The recurring period (day, week, month, year, onetime) used in conjunction with term in order to determine the next recurring payment 189 | * @return string HTML markup required to render an authorization and capture payment form 190 | */ 191 | public function buildProcess(array $contact_info, $amount, array $invoice_amounts=null, array $options=null) { 192 | $this->view = $this->makeView("process", "default", str_replace(ROOTWEBDIR, "", dirname(__FILE__) . DS)); 193 | 194 | // Load the helpers required for this view 195 | Loader::loadHelpers($this, array("Form", "Html")); 196 | 197 | $fields = array(); 198 | $post_to = ""; 199 | 200 | # 201 | # TODO: Define all form fields and the $post_to fields 202 | # 203 | 204 | $this->view->set("post_to", $post_to); 205 | $this->view->set("fields", $fields); 206 | 207 | return $this->view->fetch(); 208 | } 209 | 210 | /** 211 | * Validates the incoming POST/GET response from the gateway to ensure it is 212 | * legitimate and can be trusted. 213 | * 214 | * @param array $get The GET data for this request 215 | * @param array $post The POST data for this request 216 | * @return array An array of transaction data, sets any errors using Input if the data fails to validate 217 | * - client_id The ID of the client that attempted the payment 218 | * - amount The amount of the payment 219 | * - currency The currency of the payment 220 | * - invoices An array of invoices and the amount the payment should be applied to (if any) including: 221 | * - id The ID of the invoice to apply to 222 | * - amount The amount to apply to the invoice 223 | * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) 224 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 225 | * - transaction_id The ID returned by the gateway to identify this transaction 226 | */ 227 | public function validate(array $get, array $post) { 228 | 229 | # 230 | # TODO: Verify the get/post data, then return the transaction 231 | # 232 | # 233 | 234 | // Log the successful response 235 | $this->log($this->ifSet($_SERVER['REQUEST_URI']), serialize($post), "output", true); 236 | 237 | return array(); 238 | } 239 | 240 | /** 241 | * Returns data regarding a success transaction. This method is invoked when 242 | * a client returns from the non-merchant gateway's web site back to Blesta. 243 | * 244 | * @param array $get The GET data for this request 245 | * @param array $post The POST data for this request 246 | * @return array An array of transaction data, may set errors using Input if the data appears invalid 247 | * - client_id The ID of the client that attempted the payment 248 | * - amount The amount of the payment 249 | * - currency The currency of the payment 250 | * - invoices An array of invoices and the amount the payment should be applied to (if any) including: 251 | * - id The ID of the invoice to apply to 252 | * - amount The amount to apply to the invoice 253 | * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) 254 | * - transaction_id The ID returned by the gateway to identify this transaction 255 | */ 256 | public function success(array $get, array $post) { 257 | 258 | # 259 | # TODO: Return transaction data, if possible 260 | # 261 | 262 | $this->Input->setErrors($this->getCommonError("unsupported")); 263 | } 264 | 265 | /** 266 | * Captures a previously authorized payment 267 | * 268 | * @param string $reference_id The reference ID for the previously authorized transaction 269 | * @param string $transaction_id The transaction ID for the previously authorized transaction 270 | * @return array An array of transaction data including: 271 | * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) 272 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 273 | * - transaction_id The ID returned by the remote gateway to identify this transaction 274 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 275 | */ 276 | public function capture($reference_id, $transaction_id, $amount, array $invoice_amounts=null) { 277 | 278 | # 279 | # TODO: Return transaction data, if possible 280 | # 281 | 282 | $this->Input->setErrors($this->getCommonError("unsupported")); 283 | } 284 | 285 | /** 286 | * Void a payment or authorization 287 | * 288 | * @param string $reference_id The reference ID for the previously submitted transaction 289 | * @param string $transaction_id The transaction ID for the previously submitted transaction 290 | * @param string $notes Notes about the void that may be sent to the client by the gateway 291 | * @return array An array of transaction data including: 292 | * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) 293 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 294 | * - transaction_id The ID returned by the remote gateway to identify this transaction 295 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 296 | */ 297 | public function void($reference_id, $transaction_id, $notes=null) { 298 | 299 | # 300 | # TODO: Return transaction data, if possible 301 | # 302 | 303 | $this->Input->setErrors($this->getCommonError("unsupported")); 304 | } 305 | 306 | /** 307 | * Refund a payment 308 | * 309 | * @param string $reference_id The reference ID for the previously submitted transaction 310 | * @param string $transaction_id The transaction ID for the previously submitted transaction 311 | * @param float $amount The amount to refund this card 312 | * @param string $notes Notes about the refund that may be sent to the client by the gateway 313 | * @return array An array of transaction data including: 314 | * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) 315 | * - reference_id The reference ID for gateway-only use with this transaction (optional) 316 | * - transaction_id The ID returned by the remote gateway to identify this transaction 317 | * - message The message to be displayed in the interface in addition to the standard message for this transaction status (optional) 318 | */ 319 | public function refund($reference_id, $transaction_id, $amount, $notes=null) { 320 | 321 | # 322 | # TODO: Return transaction data, if possible 323 | # 324 | 325 | $this->Input->setErrors($this->getCommonError("unsupported")); 326 | } 327 | } 328 | ?> -------------------------------------------------------------------------------- /components/gateways/nonmerchant/nonmerchant_demo/views/default/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phillipsdata/blesta_sdk/052760da4d9468c2d49edf1482ec97d35c85f162/components/gateways/nonmerchant/nonmerchant_demo/views/default/images/logo.png -------------------------------------------------------------------------------- /components/gateways/nonmerchant/nonmerchant_demo/views/default/process.pdt: -------------------------------------------------------------------------------- 1 | 2 | Form->setCsrfOptions(array('set_on_create' => false)); 5 | $this->Form->create($post_to); 6 | if ($this->Html->ifSet($fields)) { 7 | foreach ($fields as $key => $value) { 8 | $this->Form->fieldHidden($key, $value); 9 | } 10 | } 11 | 12 | $this->Form->fieldSubmit("submit", $this->_("NonmerchantDemo.buildprocess.submit", true)); 13 | 14 | $this->Form->end(); 15 | ?> -------------------------------------------------------------------------------- /components/gateways/nonmerchant/nonmerchant_demo/views/default/settings.pdt: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------