Changeset 1752310
- Timestamp:
- 10/25/2017 08:23:46 AM (8 years ago)
- Location:
- assembly-payments-gateways
- Files:
-
- 9 added
- 10 edited
-
assets/banner-1544x500.jpg (added)
-
assets/banner-772x250.jpg (added)
-
assets/icon-128x128.jpg (added)
-
assets/icon-256x256.jpg (added)
-
assets/screenshot-1.jpg (added)
-
assets/screenshot-2.jpg (added)
-
assets/screenshot-3.jpg (added)
-
assets/screenshot-4.jpg (added)
-
assets/screenshot-5.jpg (added)
-
trunk/assembly-payment-gateways.php (modified) (7 diffs)
-
trunk/assets/js/assembly.js (modified) (1 diff)
-
trunk/includes/class-as-assembly-api.php (modified) (4 diffs)
-
trunk/includes/class-as-assembly-gateway-bank.php (modified) (4 diffs)
-
trunk/includes/class-as-assembly-gateway.php (modified) (8 diffs)
-
trunk/includes/country-code/country_code_convert.php (modified) (1 diff)
-
trunk/includes/customer/class-as-assembly-user-account.php (modified) (1 diff)
-
trunk/includes/settings-formfields-assembly-bank.php (modified) (2 diffs)
-
trunk/includes/settings-formfields-assembly.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
assembly-payments-gateways/trunk/assembly-payment-gateways.php
r1752218 r1752310 5 5 /* 6 6 * Plugin Name: Assembly Payments Gateways 7 * Plugin URI: https://wordpress.org/plugins/assembly-payments-gateways/ 7 8 * Description: Custom-made Assembly Payments Gateway 8 * Author: Assembly 9 * Version: 1.0.0 9 * Author: simonunderwood 10 * Author URI: https://assemblypayments.com/ 11 * Version: 1.0.1 12 * Text Domain: assembly-payments-gateways 10 13 */ 11 14 12 if ( !defined('ABSPATH')) {15 if ( ! defined( 'ABSPATH' ) ) { 13 16 exit; 14 17 } 15 use PromisePay\PromisePay; 16 18 define( 'AS_ASSEMBLY_VERSION', '1.0.1' ); 17 19 if (!class_exists('AS_Assembly')) { 18 20 class AS_Assembly … … 22 24 private static $log; 23 25 24 public static function get_instance() 25 { 26 public static function get_instance() { 26 27 if (null === self::$instance) { 27 28 self::$instance = new self(); … … 33 34 protected function __construct() 34 35 { 36 add_action( 'admin_init', array( $this, 'check_environment' ) ); 35 37 add_action('plugins_loaded', array($this, 'init')); 36 38 } 37 39 38 public function init() 39 { 40 public function init() { 40 41 $path = plugin_dir_path(__FILE__); 41 42 require_once $path . 'promisepay-php-master/autoload.php'; … … 46 47 $this->init_gateway(); 47 48 48 add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); 49 add_action('woocommerce_api_as_assembly_api', array($this, 'assembly_callbacks'), 10, 2); 49 add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); 50 } 51 52 public function check_environment() { 53 if ( ! defined( 'IFRAME_REQUEST' ) && ( AS_ASSEMBLY_VERSION !== get_option( 'as_assembly_version' ) ) ) { 54 $this->install(); 55 56 do_action( 'woocommerce_assembly_updated' ); 57 } 58 } 59 private static function _update_plugin_version() { 60 delete_option( 'as_assembly_version' ); 61 update_option( 'as_assembly_version', AS_ASSEMBLY_VERSION ); 62 63 return true; 64 } 65 public function install() { 66 if ( ! defined( 'AS_ASSEMBLY_INSTALLING' ) ) { 67 define( 'AS_ASSEMBLY_INSTALLING', true ); 68 } 69 70 $this->_update_plugin_version(); 50 71 } 51 72 52 73 public function woocommerce_payment_token_deleted($token_id, $token) 53 74 { 54 if ( 'assembly' === $token->get_gateway_id()) {75 if ( 'assembly' === $token->get_gateway_id() ) { 55 76 $assembly_api_obj = new AS_Assembly_API(); 56 77 $assembly_api_obj->deleteCardAccount($token->get_token()); … … 58 79 } 59 80 60 public function init_gateway() 61 { 62 if (!class_exists('WC_Payment_Gateway')) { 81 public function init_gateway() { 82 if ( ! class_exists( 'WC_Payment_Gateway' ) ) { 63 83 return; 64 84 } … … 66 86 include_once(dirname(__FILE__) . '/includes/class-as-assembly-gateway.php'); 67 87 include_once(dirname(__FILE__) . '/includes/class-as-assembly-gateway-bank.php'); 68 add_filter( 'woocommerce_payment_gateways', array($this, 'add_gateways'));88 add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); 69 89 } 70 90 71 public function add_gateways($methods) 72 { 91 public function add_gateways($methods) { 73 92 $methods[] = 'AS_Gateway_Assembly'; 74 93 $methods[] = 'AS_Gateway_Assembly_Bank'; … … 77 96 } 78 97 79 //call back 80 public function assembly_callbacks() 81 { 82 $assemblyapiobj = new AS_Assembly_API(); 83 $string = file_get_contents("php://input"); 84 $data = json_decode($string, true); 85 if (isset($data['transactions'])) { 86 if ($data['transactions']['type'] === 'payment' && $data['transactions']['state'] === 'successful') { 87 $itemId = $data['transactions']['account_id']; 88 $item = PromisePay::Item()->get($itemId); 89 $orderId = $item['custom_descriptor']; 90 $order = wc_get_order($orderId); 91 $order->payment_complete($data['transactions']['id']); 92 $order->update_status('processing', __( 'Payment held', 'assembly-payment-gateways' )); 93 update_post_meta($orderId, 'Assembly Charge ID', $data['transactions']['id']); 94 } 95 } 96 97 } 98 99 public static function log($message) 100 { 101 if (empty(self::$log)) { 98 public static function log( $message ) { 99 if ( empty( self::$log ) ) { 102 100 self::$log = new WC_Logger(); 103 101 } 104 self::$log->add( 'assembly-payment-gateways', $message);102 self::$log->add( 'assembly-payment-gateways', $message ); 105 103 } 106 104 } -
assembly-payments-gateways/trunk/assets/js/assembly.js
r1752218 r1752310 1 /**2 * Created by joel on 14/07/2017.3 */4 1 jQuery(function($) { 5 2 'use strict'; -
assembly-payments-gateways/trunk/includes/class-as-assembly-api.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 13/07/2017 6 * Time: 14:35 7 */ 2 8 3 if ( ! defined( 'ABSPATH' ) ) { 9 4 exit; … … 110 105 } 111 106 } 112 113 public static function getCardAccount($cardId) { 114 try { 115 $response = PromisePay::CardAccount()->get($cardId); 107 public static function getCardAccount($id) { 108 try { 109 $response = PromisePay::CardAccount()->get($id); 116 110 AS_Assembly::log( 'getCardAccount Response: ' . print_r( $response, true ) ); 117 if ($response) return $response; 118 else { 119 throw new Exception(__('Something went wrong while deleting card account.')); 120 } 121 } catch (Exception $e) { 122 // wc_add_notice( $e->getMessage(), 'error' ); 111 112 if ($response) return $response; 113 else { 114 throw new Exception(__('Something went wrong while get card account.')); 115 } 116 } catch (Exception $e) { 117 wc_add_notice( $e->getMessage(), 'error' ); 118 123 119 AS_Assembly::log( 'getCardAccount error Response: ' . print_r( $e->getMessage(), true ) ); 124 120 … … 131 127 $response = PromisePay::CardAccount()->delete($cardId); 132 128 AS_Assembly::log( 'deleteCardAccount Response: ' . print_r( $response, true ) ); 133 if ($response) return $response;134 else {135 throw new Exception(__('Something went wrong while deleting card account.'));136 }137 } catch (Exception $e) {138 // wc_add_notice( $e->getMessage(), 'error' );139 AS_Assembly::log( 'deleteCardAccount error Response: ' . print_r( $e->getMessage(), true ) );140 141 return;142 }143 }144 145 /**146 * @param $params147 */148 public static function createCallBacks($params) {149 try {150 $response = PromisePay::CallBacks()->create($params);151 AS_Assembly::log( 'createCallBacks Response: ' . print_r( $response, true ) );152 129 if ($response) return $response; 153 130 else { … … 184 161 "currency" => $order->get_currency(), 185 162 "retain_account" => true, 186 "custom_descriptor" => $order->get_order_number(),187 163 )); 188 164 -
assembly-payments-gateways/trunk/includes/class-as-assembly-gateway-bank.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 19/07/2017 6 * Time: 14:25 7 */ 2 8 3 class AS_Gateway_Assembly_Bank extends WC_Payment_Gateway_eCheck 9 4 { … … 29 24 $this->description2 = $this->get_option('description2'); 30 25 $this->logging = 'yes' === $this->get_option('logging'); 31 update_option('assembly_payment_bank_settings', $this->settings); 26 32 27 $ccOptions = get_option('assembly_payment_settings'); 33 28 $this->testmode = 'yes' === $ccOptions['testmode']; … … 36 31 37 32 AS_Assembly_API::set_user_credentials($this->username, $this->password, $this->testmode); 38 // Add hooks33 update_option('assembly_payment_settings_bank', $this->settings); 39 34 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 40 35 } … … 240 235 241 236 public function log( $message ) { 242 $options = get_option('assembly_payment_ bank_settings');237 $options = get_option('assembly_payment_settings'); 243 238 244 239 if ( 'yes' === $options['logging'] ) { -
assembly-payments-gateways/trunk/includes/class-as-assembly-gateway.php
r1752218 r1752310 1 1 <?php 2 2 3 /**4 * Created by PhpStorm.5 * User: joel6 * Date: 14/07/20177 * Time: 07:568 */9 3 class AS_Gateway_Assembly extends WC_Payment_Gateway_CC 10 4 { … … 48 42 AS_Assembly_API::set_user_credentials($this->username, $this->password, $this->testmode); 49 43 update_option('assembly_payment_settings', $this->settings); 50 //create callbacks 51 $params = array( 52 'description' => 'Transactions Callback', 53 'url' => get_home_url().'/wc-api/as_assembly_api/', 54 'object_type' => 'transactions', 55 'enabled' => 'true', 56 ); 57 $assemblyapiobj = new AS_Assembly_API(); 58 $assemblyapiobj->createCallBacks($params); 44 59 45 // Add hooks 60 46 add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); // not yet use this … … 131 117 data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; //todo: change this 132 118 133 // if(is_user_logged_in()){ 134 if ( $this->description1 ) { 135 echo '<p>'.wpautop( wp_kses_post( $this->description1 ) ).'</p>'; 136 } 137 138 if ($display_token) { 139 $this->saved_payment_methods(); 140 } 141 142 $this->form(); 143 144 if ($this->saved_cards) { 145 $this->save_payment_method_checkbox(); 146 } 147 // } 148 119 if ( $this->description1 ) { 120 echo '<p>'.wpautop( wp_kses_post( $this->description1 ) ).'</p>'; 121 } 122 123 if ($display_token) { 124 $this->saved_payment_methods(); 125 } 126 127 $this->form(); 128 129 if ($this->saved_cards) { 130 $this->save_payment_method_checkbox(); 131 } 149 132 150 133 echo '</div>'; … … 175 158 $createCardResponse = $assemblyApiObj->createCardAccount($body); 176 159 177 if ($createCardResponse && class_exists('WC_Payment_Token_CC') && $this->saved_cards && array_key_exists('wc-assembly-new-payment-method', $params)) { 178 $token = new WC_Payment_Token_CC(); 179 $token->set_token($createCardResponse['id']); 180 $token->set_gateway_id('assembly'); 181 182 $cardAccount = $assemblyApiObj->getCardAccount($createCardResponse['id']); 183 if(isset($cardAccount['card']['type'])) { 184 $token->set_card_type($cardAccount['card']['type']); 185 } 186 else $token->set_card_type('visa'); 187 $token->set_last4(substr($params['assembly-card-number'], -4)); 188 $token->set_expiry_month($explode[0]); 189 $token->set_expiry_year('20' . $explode[1]); 190 $token->set_user_id(get_current_user_id()); 191 $token->save(); 192 } 160 // if ($createCardResponse && class_exists('WC_Payment_Token_CC') && $this->saved_cards && array_key_exists('wc-assembly-new-payment-method', $params)) { 161 // $token = new WC_Payment_Token_CC(); 162 // $token->set_token($createCardResponse['id']); 163 // $token->set_gateway_id('assembly'); 164 // $token->set_card_type('Visa'); 165 // $token->set_last4(substr($params['assembly-card-number'], -4)); 166 // $token->set_expiry_month($explode[0]); 167 // $token->set_expiry_year('20' . $explode[1]); 168 // $token->set_user_id(get_current_user_id()); 169 // $token->save(); 170 // } 193 171 if ( 'yes' === $this->logging ) { 194 172 AS_Assembly::log( 'createUser error Request: ' . print_r( $createCardResponse, true ) ); … … 205 183 $assemblyUser = new AS_Assembly_User_Account(get_current_user_id(), $order); // get assembly user obj 206 184 185 // // start create assembly item and set order status to hold 186 // $assemblyApiObj = new SE_Assembly_API(); 187 // $itemResponse = $assemblyApiObj->createItem($assemblyUser, $order, $this->seller_id); 188 // 189 // $order->update_status('on-hold', sprintf(__('Assembly item approved (Item ID: %s). make payment, or cancel.', 'assembly-payment-gateways'), $itemResponse['id'])); 190 // // end create assembly item 191 207 192 if ($postData['wc-assembly-payment-token'] === 'new') { 208 193 $cardAccount = $this->get_card_account($assemblyUser, $postData); // assembly card account … … 211 196 $assemblyApiObj = new AS_Assembly_API(); 212 197 $makePaymentResponse = $assemblyApiObj->createCharge($cardAccount['id'], $order); 198 213 199 if (!$makePaymentResponse) { 214 200 throw new Exception(__('Something went wrong while creating charge.')); 215 201 } 216 if ($makePaymentResponse['state'] == 'completed') { 202 if ($makePaymentResponse['state'] == 'completed'||$makePaymentResponse['state'] == 'payment_held') { 203 $assemblyApiObj = new AS_Assembly_API(); 204 $getCardResponse = $assemblyApiObj->getCardAccount($cardAccount['id']); 205 if (class_exists('WC_Payment_Token_CC') && $this->saved_cards) { 206 $token = new WC_Payment_Token_CC(); 207 $token->set_token($cardAccount['id']); 208 $token->set_gateway_id('assembly'); 209 $token->set_card_type($getCardResponse['card']['type']); 210 $token->set_last4(substr($getCardResponse['card']['number'], -4)); 211 $token->set_expiry_month($getCardResponse['card']['expiry_month']); 212 $token->set_expiry_year($getCardResponse['card']['expiry_year']); 213 $token->set_user_id(get_current_user_id()); 214 $token->save(); 215 } 217 216 $order->payment_complete($makePaymentResponse['id']); 218 update_post_meta($order_id, 'Assembly Charge ID', $makePaymentResponse['id']);219 220 // Remove cart.221 WC()->cart->empty_cart();222 223 // Return thank you page redirect.224 return array(225 'result' => 'success',226 'redirect' => $this->get_return_url($order),227 );228 }229 //payment held230 if ($makePaymentResponse['state'] == 'payment_held') {231 wc_add_notice( __('Your order was on pending state!', 'assembly-payment-gateways') , 'notice' );232 $order->update_status('pending', __( 'Payment held', 'assembly-payment-gateways' ));233 217 update_post_meta($order_id, 'Assembly Charge ID', $makePaymentResponse['id']); 234 218 … … 249 233 if (!$token || $token->get_user_id() !== get_current_user_id()) { 250 234 WC()->session->set('refresh_totals', true); 251 throw new Exception(__('Invalid payment method. Please input a new card number.', ' assembly-payment-gateways'));235 throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); 252 236 } 253 237 $cardAccountId = $token->get_token(); 254 238 $assemblyApiObj = new AS_Assembly_API(); 255 239 $makePaymentResponse = $assemblyApiObj->createCharge($cardAccountId, $order); 240 256 241 if ($makePaymentResponse) { 257 242 if ($makePaymentResponse['state'] == 'completed') { … … 268 253 ); 269 254 } 270 if ($makePaymentResponse) { 271 if ($makePaymentResponse['state'] == 'payment_held') { 272 wc_add_notice( __('Your order was on pending state!', 'assembly-payment-gateways') , 'notice' ); 273 $order->update_status('pending', __( 'Payment held', 'assembly-payment-gateways' )); 274 update_post_meta($order_id, 'Assembly Charge ID', $makePaymentResponse['id']); 275 276 // Remove cart. 277 WC()->cart->empty_cart(); 278 279 // Return thank you page redirect. 280 return array( 281 'result' => 'success', 282 'redirect' => $this->get_return_url($order), 283 ); 284 } 285 } 286 } 287 else { 255 } else { 288 256 throw new Exception(__('Something went wrong while capturing the payment.')); 289 257 } -
assembly-payments-gateways/trunk/includes/country-code/country_code_convert.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 18/07/2017 6 * Time: 03:13 7 */ 2 8 3 function kia_convert_country_code( $country ) { 9 4 $countries = array( -
assembly-payments-gateways/trunk/includes/customer/class-as-assembly-user-account.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 17/07/2017 6 * Time: 13:19 7 */ 2 8 3 if ( ! defined( 'ABSPATH' ) ) { 9 4 exit; -
assembly-payments-gateways/trunk/includes/settings-formfields-assembly-bank.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 19/07/2017 6 * Time: 16:30 7 */ 2 8 3 if ( ! defined( 'ABSPATH' ) ) { 9 4 exit; … … 28 23 'description2' => array( 29 24 'title' => __( 'Description', 'assembly-payment-gateways-bank' ), 30 'type' => 'text ',25 'type' => 'textarea', 31 26 'description' => __( 'This controls the description which the user sees during checkout.', 'assembly-payment-gateways-bank' ), 32 'default' => __( 'Payment Instructions Bank account: Routing number: 123123. Account number : 12341234. Country: Australia', 'assembly-payment-gateways-bank' ), 27 'default' => __( 'Payment Instructions Bank account: 28 Routing number: 123123. 29 Account number : 12341234. 30 Country: Australia', 'assembly-payment-gateways-bank' ), 33 31 'desc_tip' => true, 34 32 ), -
assembly-payments-gateways/trunk/includes/settings-formfields-assembly.php
r1752218 r1752310 1 1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: joel 5 * Date: 14/07/2017 6 * Time: 08:04 7 */ 2 8 3 if ( ! defined( 'ABSPATH' ) ) { 9 4 exit; … … 28 23 'description1' => array( 29 24 'title' => __( 'Description Credit Card', 'assembly-payment-gateways' ), 30 'type' => 'text ',25 'type' => 'textarea', 31 26 'description' => __( 'This controls the description which the user sees during checkout.', 'assembly-payment-gateways' ), 32 'default' => __( 'Payment Instructions Credit card: 33 Card: 4111111111111111. CCV : 123. Account Name: User full name with atleast a space. Exp date: In future', 'assembly-payment-gateways' ), 27 'default' => __( ' 28 Payment Instructions Credit card: 29 Card: 4111111111111111. 30 CCV : 123. 31 Account Name: User full name with atleast a space. 32 Exp date: In future', 'assembly-payment-gateways' ), 34 33 'desc_tip' => true, 35 34 ), … … 51 50 'password' => array( 52 51 'title' => __( 'Password', 'assembly-payment-gateways' ), 53 'type' => ' password',52 'type' => 'text', 54 53 'description' => __( 'Password', 'assembly-payment-gateways' ), 55 54 'default' => '', -
assembly-payments-gateways/trunk/readme.txt
r1752218 r1752310 131 131 == Changelog == 132 132 133 = 1.0.1 = 134 * Fix bugs when checking out with credit cards 135 * Fix bugs not being able to identify card brands 136 * Fix bugs when checking out with bank direct debit 137 * Fix bugs related to saved cards 138 133 139 = 1.0 = 134 140 * First version … … 138 144 139 145 == Upgrade Notice == 146 147 = 1.0.1 = 148 149 * You should upgrade the plugin to this version to ensure stable operation 140 150 141 151 = 1.0 =
Note: See TracChangeset
for help on using the changeset viewer.