Plugin Directory

Changeset 1752310


Ignore:
Timestamp:
10/25/2017 08:23:46 AM (8 years ago)
Author:
simonunderwood
Message:

Version 1.0.1 - Fix bugs

  • Fix bugs when checking out with credit cards
  • Fix bugs not being able to identify card brands
  • Fix bugs when checking out with bank direct debit
  • Fix bugs related to saved cards
Location:
assembly-payments-gateways
Files:
9 added
10 edited

Legend:

Unmodified
Added
Removed
  • assembly-payments-gateways/trunk/assembly-payment-gateways.php

    r1752218 r1752310  
    55/*
    66 * Plugin Name: Assembly Payments Gateways
     7 * Plugin URI: https://wordpress.org/plugins/assembly-payments-gateways/
    78 * 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
    1013*/
    1114
    12 if (!defined('ABSPATH')) {
     15if ( ! defined( 'ABSPATH' ) ) {
    1316    exit;
    1417}
    15 use PromisePay\PromisePay;
    16 
     18define( 'AS_ASSEMBLY_VERSION', '1.0.1' );
    1719if (!class_exists('AS_Assembly')) {
    1820    class AS_Assembly
     
    2224        private static $log;
    2325
    24         public static function get_instance()
    25         {
     26        public static function get_instance() {
    2627            if (null === self::$instance) {
    2728                self::$instance = new self();
     
    3334        protected function __construct()
    3435        {
     36            add_action( 'admin_init', array( $this, 'check_environment' ) );
    3537            add_action('plugins_loaded', array($this, 'init'));
    3638        }
    3739
    38         public function init()
    39         {
     40        public function init() {
    4041            $path = plugin_dir_path(__FILE__);
    4142            require_once $path . 'promisepay-php-master/autoload.php';
     
    4647            $this->init_gateway();
    4748
    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();
    5071        }
    5172
    5273        public function woocommerce_payment_token_deleted($token_id, $token)
    5374        {
    54             if ('assembly' === $token->get_gateway_id()) {
     75            if ( 'assembly' === $token->get_gateway_id() ) {
    5576                $assembly_api_obj = new AS_Assembly_API();
    5677                $assembly_api_obj->deleteCardAccount($token->get_token());
     
    5879        }
    5980
    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' ) ) {
    6383                return;
    6484            }
     
    6686            include_once(dirname(__FILE__) . '/includes/class-as-assembly-gateway.php');
    6787            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' ) );
    6989        }
    7090
    71         public function add_gateways($methods)
    72         {
     91        public function add_gateways($methods) {
    7392            $methods[] = 'AS_Gateway_Assembly';
    7493            $methods[] = 'AS_Gateway_Assembly_Bank';
     
    7796        }
    7897
    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 ) ) {
    102100                self::$log = new WC_Logger();
    103101            }
    104             self::$log->add('assembly-payment-gateways', $message);
     102            self::$log->add( 'assembly-payment-gateways', $message );
    105103        }
    106104    }
  • assembly-payments-gateways/trunk/assets/js/assembly.js

    r1752218 r1752310  
    1 /**
    2  * Created by joel on 14/07/2017.
    3  */
    41jQuery(function($) {
    52    'use strict';
  • assembly-payments-gateways/trunk/includes/class-as-assembly-api.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 13/07/2017
    6  * Time: 14:35
    7  */
     2
    83if ( ! defined( 'ABSPATH' ) ) {
    94    exit;
     
    110105        }
    111106    }
    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);
    116110            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
    123119            AS_Assembly::log(  'getCardAccount error Response: ' . print_r( $e->getMessage(), true ) );
    124120
     
    131127            $response = PromisePay::CardAccount()->delete($cardId);
    132128            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 $params
    147      */
    148     public static function createCallBacks($params) {
    149         try {
    150             $response = PromisePay::CallBacks()->create($params);
    151             AS_Assembly::log(  'createCallBacks Response: ' . print_r( $response, true ) );
    152129            if ($response) return $response;
    153130            else {
     
    184161                "currency" => $order->get_currency(),
    185162                "retain_account" => true,
    186                 "custom_descriptor" => $order->get_order_number(),
    187163            ));
    188164
  • assembly-payments-gateways/trunk/includes/class-as-assembly-gateway-bank.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 19/07/2017
    6  * Time: 14:25
    7  */
     2
    83class AS_Gateway_Assembly_Bank extends WC_Payment_Gateway_eCheck
    94{
     
    2924        $this->description2 = $this->get_option('description2');
    3025        $this->logging = 'yes' === $this->get_option('logging');
    31         update_option('assembly_payment_bank_settings', $this->settings);
     26
    3227        $ccOptions = get_option('assembly_payment_settings');
    3328        $this->testmode = 'yes' === $ccOptions['testmode'];
     
    3631
    3732        AS_Assembly_API::set_user_credentials($this->username, $this->password, $this->testmode);
    38         // Add hooks
     33        update_option('assembly_payment_settings_bank', $this->settings);
    3934        add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
    4035    }
     
    240235
    241236    public function log( $message ) {
    242         $options = get_option('assembly_payment_bank_settings');
     237        $options = get_option('assembly_payment_settings');
    243238
    244239        if ( 'yes' === $options['logging'] ) {
  • assembly-payments-gateways/trunk/includes/class-as-assembly-gateway.php

    r1752218 r1752310  
    11<?php
    22
    3 /**
    4  * Created by PhpStorm.
    5  * User: joel
    6  * Date: 14/07/2017
    7  * Time: 07:56
    8  */
    93class AS_Gateway_Assembly extends WC_Payment_Gateway_CC
    104{
     
    4842        AS_Assembly_API::set_user_credentials($this->username, $this->password, $this->testmode);
    4943        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
    5945        // Add hooks
    6046        add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); // not yet use this
     
    131117            data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; //todo: change this
    132118
    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        }
    149132
    150133        echo '</div>';
     
    175158        $createCardResponse = $assemblyApiObj->createCardAccount($body);
    176159
    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//        }
    193171        if ( 'yes' === $this->logging ) {
    194172            AS_Assembly::log(  'createUser error Request: ' . print_r( $createCardResponse, true ) );
     
    205183            $assemblyUser = new AS_Assembly_User_Account(get_current_user_id(), $order); // get assembly user obj
    206184
     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
    207192            if ($postData['wc-assembly-payment-token'] === 'new') {
    208193                $cardAccount = $this->get_card_account($assemblyUser, $postData); // assembly card account
     
    211196                    $assemblyApiObj = new AS_Assembly_API();
    212197                    $makePaymentResponse = $assemblyApiObj->createCharge($cardAccount['id'], $order);
     198
    213199                    if (!$makePaymentResponse) {
    214200                        throw new Exception(__('Something went wrong while creating charge.'));
    215201                    }
    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                            }
    217216                        $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 held
    230                     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' ));
    233217                        update_post_meta($order_id, 'Assembly Charge ID', $makePaymentResponse['id']);
    234218
     
    249233                if (!$token || $token->get_user_id() !== get_current_user_id()) {
    250234                    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'));
    252236                }
    253237                $cardAccountId = $token->get_token();
    254238                $assemblyApiObj = new AS_Assembly_API();
    255239                $makePaymentResponse = $assemblyApiObj->createCharge($cardAccountId, $order);
     240
    256241                if ($makePaymentResponse) {
    257242                    if ($makePaymentResponse['state'] == 'completed') {
     
    268253                        );
    269254                    }
    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 {
    288256                    throw new Exception(__('Something went wrong while capturing the payment.'));
    289257                }
  • assembly-payments-gateways/trunk/includes/country-code/country_code_convert.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 18/07/2017
    6  * Time: 03:13
    7  */
     2
    83function kia_convert_country_code( $country ) {
    94    $countries = array(
  • assembly-payments-gateways/trunk/includes/customer/class-as-assembly-user-account.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 17/07/2017
    6  * Time: 13:19
    7  */
     2
    83if ( ! defined( 'ABSPATH' ) ) {
    94    exit;
  • assembly-payments-gateways/trunk/includes/settings-formfields-assembly-bank.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 19/07/2017
    6  * Time: 16:30
    7  */
     2
    83if ( ! defined( 'ABSPATH' ) ) {
    94    exit;
     
    2823        'description2' => array(
    2924            'title'       => __( 'Description', 'assembly-payment-gateways-bank' ),
    30             'type'        => 'text',
     25            'type'        => 'textarea',
    3126            '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' ),
    3331            'desc_tip'    => true,
    3432        ),
  • assembly-payments-gateways/trunk/includes/settings-formfields-assembly.php

    r1752218 r1752310  
    11<?php
    2 /**
    3  * Created by PhpStorm.
    4  * User: joel
    5  * Date: 14/07/2017
    6  * Time: 08:04
    7  */
     2
    83if ( ! defined( 'ABSPATH' ) ) {
    94    exit;
     
    2823        'description1' => array(
    2924            'title'       => __( 'Description Credit Card', 'assembly-payment-gateways' ),
    30             'type'        => 'text',
     25            'type'        => 'textarea',
    3126            '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' ),
    3433            'desc_tip'    => true,
    3534        ),
     
    5150        'password' => array(
    5251            'title'       => __( 'Password', 'assembly-payment-gateways' ),
    53             'type'        => 'password',
     52            'type'        => 'text',
    5453            'description' => __( 'Password', 'assembly-payment-gateways' ),
    5554            'default'     => '',
  • assembly-payments-gateways/trunk/readme.txt

    r1752218 r1752310  
    131131== Changelog ==
    132132
     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
    133139= 1.0 =
    134140* First version
     
    138144
    139145== Upgrade Notice ==
     146
     147= 1.0.1 =
     148
     149* You should upgrade the plugin to this version to ensure stable operation
    140150 
    141151= 1.0 =
Note: See TracChangeset for help on using the changeset viewer.