Plugin Directory

Changeset 2094189


Ignore:
Timestamp:
05/24/2019 01:05:08 AM (7 years ago)
Author:
payadvantage
Message:

Version 2.0.0

Location:
pay-advantage/trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • pay-advantage/trunk/README.txt

    r2044255 r2094189  
    44Requires at least: 4.6
    55Tested up to: 5.1
    6 Stable tag: 1.1.0
     6Stable tag: 2.0.0
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    4747
    4848= 1.1.0 =
    49 * Multiple updates, bug fixes and general imporovements. Please ensure you update to this version.
     49* Multiple updates, bug fixes and general improvements. Please ensure you update to this version.
     50
     51= 2.0.0 =
     52* Multiple updates, settings page improvements. Please ensure you update to this version.
  • pay-advantage/trunk/admin/html/options-html.php

    r2017348 r2094189  
    3131            <table class="form-table">
    3232                <tbody>
     33                    <tr>
     34                        <th>
     35                            <label for="payAdvantageEnv">API Environment</label>
     36                        </th>
     37                        <td>
     38                            <input class="regular-text" type="radio" id="payAdvantageEnv" name="payAdvantageEnv" value="sandbox" <?php echo esc_attr( get_option('pay_advantage_env') ) != "live" ? "checked" : ""; ?>/> Sandbox
     39                            <input class="regular-text" type="radio" id="payAdvantageEnv" name="payAdvantageEnv" value="live" <?php echo esc_attr( get_option('pay_advantage_env') ) == "live" ? "checked" : ""; ?>/> Live
     40                        </td>
     41                    </tr>
    3342                    <tr>
    3443                        <th>
  • pay-advantage/trunk/admin/initialize-options.php

    r2040227 r2094189  
    66// Creates columns in the database.
    77function pay_advantage_register_settings() {
     8    add_option( 'pay_advantage_env', 'sandbox' );
     9    add_option( 'pay_advantage_url', '' );
    810    add_option( 'pay_advantage_user_name', '' );
    911    add_option( 'pay_advantage_password', '' );
  • pay-advantage/trunk/admin/js/options-page.js

    r1946429 r2094189  
    66    e.preventDefault()
    77    const anonymousPermission = $('#payAdvantageAnonymousPermission').prop('checked')
     8    const env = $('#payAdvantageEnv:checked').val()
    89    const username = $('#payAdvantageUsername').val()
    910    const password = $('#payAdvantagePassword').val()
     
    1617
    1718    const payload = {
     19      'payadvantageenv': env,
    1820      'payadvantageusername': username,
    1921      'payadvantagepassword': password,
     
    6668  const username = jQuery('#payAdvantageUsername').val()
    6769  const password = jQuery('#payAdvantagePassword').val()
     70  const env = jQuery('#payAdvantageEnv:checked').val()
    6871  var payload = {
     72    'payadvantageenv': env,
    6973    'payadvantageusername': username,
    7074    'payadvantagepassword': password
    7175  }
     76
     77  jQuery('#payAdvantageAuthCheck').text('');
    7278
    7379  payAdvantageAjaxCall('pay_advantage_test_auth_action', payload)
  • pay-advantage/trunk/admin/options-ajax.php

    r2040227 r2094189  
    2626    }
    2727
     28    $env = sanitize_user( $_POST['payadvantageenv'] );
    2829    $username = sanitize_user( $_POST['payadvantageusername'] );
    2930    $password = wp_strip_all_tags( $_POST['payadvantagepassword'] );
     
    3536    $anonymous_permission = filter_var( $_POST["payadvantageanonymouspermission"], FILTER_VALIDATE_BOOLEAN ) ? 1 : 0;
    3637
     38    $url = $env == "live" ? PAYADV_API_URL_LIVE : PAYADV_API_URL_SANDBOX;
     39
     40    update_option( 'pay_advantage_url', $url );
     41    update_option( 'pay_advantage_env', $env );
    3742    update_option( 'pay_advantage_user_name', $username );
    3843    update_option( 'pay_advantage_password', $password );
     
    7984
    8085    // TODO: Sanitize
     86    $env = sanitize_user($_POST['payadvantageenv']);
    8187    $username = sanitize_user($_POST['payadvantageusername']);
    8288    $password = wp_strip_all_tags( $_POST['payadvantagepassword'] );
    8389
    8490    $auth_data = array(
    85         'grant_type' => "password",
    8691        'username' => $username,
    8792        'password' => $password
    8893    );
    89     $return_data = $auth->get_auth_token( json_encode( $auth_data ) );
     94
     95    $url = $env == "live" ? PAYADV_API_URL_LIVE : PAYADV_API_URL_SANDBOX;
     96    $return_data = $auth->get_auth_token( $auth_data, $url );
    9097
    9198    if (!isset($return_data['ErrorMessages'])) {
  • pay-advantage/trunk/includes/class-payadvantage-deactivator.php

    r1946429 r2094189  
    1414     */
    1515    public static function deactivate() {
     16        delete_option( 'pay_advantage_env' );
     17        delete_option( 'pay_advantage_url' );
    1618        delete_option( 'pay_advantage_user_name' );
    1719        delete_option( 'pay_advantage_password' );
  • pay-advantage/trunk/payadvantage.php

    r2040278 r2094189  
    1616 * Plugin URI:        https://www.payadvantage.com.au/
    1717 * Description:       This plugin adds a payment gateway to woo commerce as well as a widget for credit card and BPay donations.
    18  * Version:           1.1.0
     18 * Version:           2.0.0
    1919 * Author:            Pay Advantage
    20  * Author URI:        https://www.payadvantage.com.au/
     20 * Author URI:        ben.m@payadvantage.com
    2121 * License:           GPL-2.0+
    2222 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    2525 */
    2626
    27 
    28 
    2927/**
    3028 * Currently plugin version.
     
    3230 * Rename this for your plugin and update it as you release new versions.
    3331 */
    34 define( 'PayAdvantage', '1.1.0' );
     32define( 'PayAdvantage', '2.0.0' );
    3533
    3634include( plugin_dir_path( __FILE__ ) . '/includes/payadvantage-files.php');
    3735
    3836// Constants
    39 define( 'PAYADV_API_URL', 'https://api.payadvantage.com.au/latest' );
     37define( 'PAYADV_APP_ID', 'wp-payadv' );
     38define( 'PAYADV_API_URL_SANDBOX', 'https://api.test.payadvantage.com.au/latest' );
     39define( 'PAYADV_API_URL_LIVE', 'https://api.payadvantage.com.au/latest' );
    4040define( 'PAYADV_OPTIONS_REQUIRE_MOBILE', 1 );
    4141define( 'PAYADV_OPTIONS_REQUIRE_ADDRESS', 0 );
  • pay-advantage/trunk/public/html/bpay-tab-html.php

    r2040227 r2094189  
    2929                        </div>
    3030                    </div>
     31
     32                    <?php if (esc_attr(get_option('pay_advantage_env')) != "live"):?>
     33                        <h4 style="color:red">Sandbox environment</h4>
     34                    <?php endif;?>
    3135                   
    3236                    <p>
  • pay-advantage/trunk/public/html/creditcard-tab-html.php

    r2040227 r2094189  
    2020                    </div>
    2121                </div>
    22                
     22                <?php if (esc_attr(get_option('pay_advantage_env')) != "live"):?>
     23                    <h4 style="color:red">Sandbox environment</h4>
     24                <?php endif;?>
    2325                <h4>
    2426                  A bit about you
  • pay-advantage/trunk/public/html/woocommerce-payment-fields-html.php

    r2040227 r2094189  
    99function pay_advantage_woocommerce_payment_fields() {
    1010    ?>
     11        <?php if (esc_attr(get_option('pay_advantage_env')) != "live"):?>
     12            <h4 style="color:red">Sandbox environment</h4>
     13        <?php endif;?>
    1114        <p class="form-row validation-required">
    1215                <label for="payAdvantageCardHoldersName">Card Holders Name <span class="required">*</span></label>
  • pay-advantage/trunk/public/payadvantage-bpay-register-api-call.php

    r2040227 r2094189  
    33 * Calls the BPay registration api
    44 */
    5 include_once( plugin_dir_path( __FILE__ ) . '../shared/payadvantage-result-processor.php' );
     5include_once(plugin_dir_path(__FILE__) . '../shared/payadvantage-result-processor.php');
    66
    7 function pay_advantage_api_call( $json_data ) {
    8     $result_processor = new Pay_Advantage_Result_Processor();
    9     $auth_provider = new Pay_Advantage_Auth();
    10     $token = $auth_provider->get_auth_token( null );
    11        
    12     if (isset($token['ErrorMessages']) > 0)
    13       return $token;
    14          
    15     $access_token = $token['access_token'];
     7function pay_advantage_api_call($json_data)
     8{
     9  $result_processor = new Pay_Advantage_Result_Processor();
     10  $auth_provider = new Pay_Advantage_Auth();
     11  $token = $auth_provider->get_auth_token(null, null);
    1612
    17     $url = PAYADV_API_URL . '/customers?with=bpayref';
    18     $body = $json_data;
    19     $data = array(
    20       'headers' => array(
    21         'Content-Type' => 'application/json',
    22         'Expect' => '',
    23         'Authorization' => "Bearer $access_token"
    24       ),
    25       'body' => $body
    26     );
    27     $response = wp_remote_post( $url, $data );
     13  if (isset($token['ErrorMessages']) > 0)
     14    return $token;
    2815
    29     return $result_processor->process_result( $response, 'BPay Registration', 'bpay' );
     16  $access_token = $token['access_token'];
     17
     18  $url = get_option('pay_advantage_url') . '/customers?with=bpayref';
     19  $body = $json_data;
     20  $data = array(
     21    'headers' => array(
     22      'Content-Type' => 'application/json',
     23      'Expect' => '',
     24      'Authorization' => "Bearer $access_token"
     25    ),
     26    'body' => $body,
     27    'timeout' => 30 // Bpay reference with the prefix option take more time to be generated
     28  );
     29  $response = wp_remote_post($url, $data);
     30
     31  return $result_processor->process_result($response, 'BPay Registration', 'bpay');
    3032}
    31 
    32 ?>
  • pay-advantage/trunk/public/payadvantage-creditcard-ajax.php

    r1946429 r2094189  
    3939   
    4040    $payment_result = $credit_card_payment->process_credit_card_payment(
    41         null,
    4241        $billing_data,
    4342        sanitize_text_field( $_POST['payadvantageamount'] ),
  • pay-advantage/trunk/public/payadvantage-creditcard.php

    r2040227 r2094189  
    44 */
    55
    6 include_once( plugin_dir_path( __FILE__ ) . '/payadvantage-json-converter.php' );
    7 include_once( plugin_dir_path( __FILE__ ) . '/payadvantage-validator.php' );
    8 include_once( plugin_dir_path( __FILE__ ) . '../shared/payadvantage-result-processor.php' );
     6include_once(plugin_dir_path(__FILE__) . '/payadvantage-json-converter.php');
     7include_once(plugin_dir_path(__FILE__) . '/payadvantage-validator.php');
     8include_once(plugin_dir_path(__FILE__) . '../shared/payadvantage-result-processor.php');
    99
     10class Pay_Advantage_Credit_Card_Payment
     11{
    1012
    11 class Pay_Advantage_Credit_Card_Payment {
     13  protected $pay_advantage_url = '';
     14  protected $access_token = '';
    1215
    13     protected $pay_advantage_url = '';
    14     protected $access_token = '';
    15    
    16     /**
    17      * This method orchestrates the credit card payments,
    18      */
    19     public function process_credit_card_payment( $auth, $billing_data, $amount, $description ) {
    20         $json_converter = new Pay_Advantage_Json_Converter();
    21         $auth_provider = new Pay_Advantage_Auth();
    22         $this->pay_advantage_url = PAYADV_API_URL;
    23         $token = $auth_provider->get_auth_token( $auth );
    24        
    25         if (isset($token['ErrorMessages']) > 0)
    26           return $token;
    27          
    28         $this->access_token = $token['access_token'];
     16  /**
     17   * This method orchestrates the credit card payments,
     18   */
     19  public function process_credit_card_payment($billing_data, $amount, $description)
     20  {
     21    $json_converter = new Pay_Advantage_Json_Converter();
     22    $auth_provider = new Pay_Advantage_Auth();
     23    $this->pay_advantage_url = get_option('pay_advantage_url');
     24    $token = $auth_provider->get_auth_token(null, null);
    2925
    30         $customer_code = $this->get_customer_code( $billing_data );
    31         if ( isset( $existing_customer['ErrorMessages'] ) ) {
    32             return $customer_code;
    33         }
    34        
    35         $json_credit_card_token_request = $json_converter->create_credit_card_token_json( $customer_code );
    36         $credit_card_token = $this->create_token_for_credit_card( $json_credit_card_token_request );
     26    if (isset($token['ErrorMessages']) > 0)
     27      return $token;
    3728
    38         if ( isset( $credit_card_token['ErrorMessages'] ) ) {
    39             return $credit_card_token;
    40         }
     29    $this->access_token = $token['access_token'];
    4130
    42         $json_charge = $json_converter->create_payment_credit_card_charge_json( $amount, $description );
    43         $payment_result = $this->charge_credit_card( $credit_card_token['Code'], $json_charge );
    44         return $payment_result;
    45     }
    46    
    47     /**
    48      * Gets the customer code, creates the customer if it has to or returns an error.
    49      */
    50     private function get_customer_code( $billing_data ) {
    51         $json_converter = new Pay_Advantage_Json_Converter();
    52         $query_customer_result = $this->customer_query_api_call(
    53           $billing_data['email'],
    54           $billing_data['first_name'],
    55           $billing_data['last_name']
    56         );
    57         if ( isset( $query_customer_result['ErrorMessages'] ) ) {
    58             return $query_customer_result;
    59         }
    60        
    61         $existing_customer = $query_customer_result['Records'];
    62 
    63         if ( $existing_customer == array() ) {
    64             $json_customer = $json_converter->create_customer_json( $billing_data );
    65             $customer = $this->create_customer_for_credit_card_payment( $json_customer );
    66 
    67             if ( isset( $existing_customer['ErrorMessages'] ) ) {
    68                 return $existing_customer;
    69             }
    70            
    71             return $customer_code = $customer['Code'];
    72         } else {
    73             return $customer_code = $existing_customer[0]['Code'];
    74         }
     31    $customer_code = $this->get_customer_code($billing_data);
     32    if (isset($customer_code['ErrorMessages'])) {
     33      return $customer_code;
    7534    }
    7635
    77     /**
    78      * Queries the customer to see if their existing.
    79      */
    80     private function customer_query_api_call( $email, $first_name, $last_name ) {
    81         $result_processor = new Pay_Advantage_Result_Processor();
    82         $url = "$this->pay_advantage_url/customers?email=$email&firstname=$first_name&lastname=$last_name";
    83         $headers = array(
    84           'headers' => array(
    85             'Content-Type' => 'application/json',
    86             'Authorization' => "Bearer $this->access_token"
    87           )
    88         );
     36    $json_credit_card_token_request = $json_converter->create_credit_card_token_json($customer_code);
     37    $credit_card_token = $this->create_token_for_credit_card($json_credit_card_token_request);
    8938
    90         $response = wp_remote_get( $url, $headers );
    91         return $result_processor->process_result( $response, 'Query', 'creditcard' );
     39    if (isset($credit_card_token['ErrorMessages'])) {
     40      return $credit_card_token;
    9241    }
    9342
    94     /**
    95      * Creates customer
    96      */
    97     private function  create_customer_for_credit_card_payment( $json_customer ) {
    98         $result_processor = new Pay_Advantage_Result_Processor();
    99         $json_converter = new Pay_Advantage_Json_Converter();
    100         $url = "$this->pay_advantage_url/customers";
    101         $data = array(
    102           'headers' => array(
    103             'Content-Type' => 'application/json',
    104             'Expect' => '',
    105             'Authorization' => "Bearer $this->access_token"
    106           ),
    107           'body' => $json_customer
    108         );
     43    $json_charge = $json_converter->create_payment_credit_card_charge_json($amount, $description);
     44    $payment_result = $this->charge_credit_card($credit_card_token['Code'], $json_charge);
     45    return $payment_result;
     46  }
    10947
    110         $response = wp_remote_post( $url, $data );
    111 
    112         return $result_processor->process_result( $response, 'Query', 'creditcard' );
     48  /**
     49   * Gets the customer code, creates the customer if it has to or returns an error.
     50   */
     51  private function get_customer_code($billing_data)
     52  {
     53    $json_converter = new Pay_Advantage_Json_Converter();
     54    $query_customer_result = $this->customer_query_api_call(
     55      $billing_data['email'],
     56      $billing_data['first_name'],
     57      $billing_data['last_name']
     58    );
     59    if (isset($query_customer_result['ErrorMessages'])) {
     60      return $query_customer_result;
    11361    }
    11462
    115     /**
    116      * Hits api for Credit Card token
    117      */
    118     private function create_token_for_credit_card( $json_card_info ) {
    119         $result_processor = new Pay_Advantage_Result_Processor();
    120         $url = "$this->pay_advantage_url/credit_cards";
    121         $data = array(
    122           'headers' => array(
    123             'Content-Type' => 'application/json',
    124             'Expect' => '',
    125             'Authorization' => "Bearer $this->access_token"
    126           ),
    127           'body' => $json_card_info
    128         );
     63    $existing_customer = $query_customer_result['Records'];
    12964
    130         $response = wp_remote_post( $url, $data );
     65    if ($existing_customer == array()) {
     66      $json_customer = $json_converter->create_customer_json($billing_data);
     67      $customer = $this->create_customer_for_credit_card_payment($json_customer);
    13168
    132         return $result_processor->process_result( $response, 'token', 'creditcard' );
     69      if (isset($customer['ErrorMessages'])) {
     70        return $customer;
     71      }
     72
     73      return $customer_code = $customer['Code'];
     74    } else {
     75      return $customer_code = $existing_customer[0]['Code'];
    13376    }
     77  }
    13478
    135     /**
    136      * Sends the api call to charge the consumer.
    137      */
    138     private function charge_credit_card( $credit_card_code, $charges_json ) {
    139         $result_processor = new Pay_Advantage_Result_Processor();
    140         $url = "$this->pay_advantage_url/credit_cards/$credit_card_code/charges";
    141         $data = array(
    142           'headers' => array(
    143             'Content-Type' => 'application/json',
    144             'Expect' => '',
    145             'Authorization' => "Bearer $this->access_token"
    146           ),
    147           'body' => $charges_json
    148         );
     79  /**
     80   * Queries the customer to see if their existing.
     81   */
     82  private function customer_query_api_call($email, $first_name, $last_name)
     83  {
     84    $result_processor = new Pay_Advantage_Result_Processor();
     85    $url = "$this->pay_advantage_url/customers?email=$email&firstname=$first_name&lastname=$last_name";
     86    $headers = array(
     87      'headers' => array(
     88        'Content-Type' => 'application/json',
     89        'Authorization' => "Bearer $this->access_token"
     90      )
     91    );
    14992
    150         $response = wp_remote_post( $url, $data );
     93    $response = wp_remote_get($url, $headers);
     94    return $result_processor->process_result($response, 'Query', 'creditcard');
     95  }
    15196
    152         return $result_processor->process_result( $response, 'charge', 'creditcard' );
    153     }
     97  /**
     98   * Creates customer
     99   */
     100  private function  create_customer_for_credit_card_payment($json_customer)
     101  {
     102    $result_processor = new Pay_Advantage_Result_Processor();
     103    $json_converter = new Pay_Advantage_Json_Converter();
     104    $url = "$this->pay_advantage_url/customers";
     105    $data = array(
     106      'headers' => array(
     107        'Content-Type' => 'application/json',
     108        'Expect' => '',
     109        'Authorization' => "Bearer $this->access_token"
     110      ),
     111      'body' => $json_customer
     112    );
     113
     114    $response = wp_remote_post($url, $data);
     115
     116    return $result_processor->process_result($response, 'Query', 'creditcard');
     117  }
     118
     119  /**
     120   * Hits api for Credit Card token
     121   */
     122  private function create_token_for_credit_card($json_card_info)
     123  {
     124    $result_processor = new Pay_Advantage_Result_Processor();
     125    $url = "$this->pay_advantage_url/credit_cards";
     126    $data = array(
     127      'headers' => array(
     128        'Content-Type' => 'application/json',
     129        'Expect' => '',
     130        'Authorization' => "Bearer $this->access_token"
     131      ),
     132      'body' => $json_card_info
     133    );
     134
     135    $response = wp_remote_post($url, $data);
     136
     137    return $result_processor->process_result($response, 'token', 'creditcard');
     138  }
     139
     140  /**
     141   * Sends the api call to charge the consumer.
     142   */
     143  private function charge_credit_card($credit_card_code, $charges_json)
     144  {
     145    $result_processor = new Pay_Advantage_Result_Processor();
     146    $url = "$this->pay_advantage_url/credit_cards/$credit_card_code/charges";
     147    $data = array(
     148      'headers' => array(
     149        'Content-Type' => 'application/json',
     150        'Expect' => '',
     151        'Authorization' => "Bearer $this->access_token"
     152      ),
     153      'body' => $charges_json
     154    );
     155
     156    $response = wp_remote_post($url, $data);
     157
     158    return $result_processor->process_result($response, 'charge', 'creditcard');
     159  }
    154160}
    155 
    156 ?>
  • pay-advantage/trunk/public/payadvantage-woocommerce.php

    r2017348 r2094189  
    140140    private function process_credit_card_payment( $billing_data, $amount, $description ) {
    141141        $credit_card_api = new Pay_Advantage_Credit_Card_Payment();
    142         $auth_data = array(
    143             "grant_type" => "password",
    144             "username" => $this->api_username,
    145             "password" => $this->api_password
    146         );
    147142
    148         $result = $credit_card_api->process_credit_card_payment( json_encode( $auth_data ), $billing_data, $amount, $description );
     143        $result = $credit_card_api->process_credit_card_payment( $billing_data, $amount, $description );
    149144
    150145        if ( isset( $result['ErrorMessages'] ) ) {
  • pay-advantage/trunk/shared/payadvantage-api-error-handler.php

    r2040227 r2094189  
    44 */
    55
    6  class Pay_Advantage_Api_Error_Handler {
     6class Pay_Advantage_Api_Error_Handler
     7{
    78    /**
    89     * The main function that looks for errors and tries to spit out some generic ones.
    9     */
    10     public function check_for_errors( $api_result, $type, $stage, $code ) {
    11         if ( $api_result == null || $code == 404 ) {
    12            return '{"type":"' . $type . '", "ErrorMessages":["Error communicating with PayAdvantage."] , "console":"' . $stage . '"}';
     10     */
     11    public function check_for_errors($api_result, $type, $stage, $code)
     12    {
     13        if ($api_result == null || $code == 404) {
     14            return '{"type":"' . $type . '", "ErrorMessages":["Error communicating with PayAdvantage."] , "console":"' . $stage . '"}';
    1315        }
    1416
    15         if ( $code >= 500) {
     17        if ($code > 500) {
    1618            return '{"type":"' . $type . '", "ErrorMessages":["Internal Error has occurred."] , "console":"' . $stage . '"}';
    1719        }
    1820
    19         $json_api_response = json_decode( $api_result, 1 );
     21        $json_api_response = json_decode($api_result, 1);
    2022
    21         if ( isset( $json_api_response['ErrorCode'] ) && (isset($json_api_response['Messages']) || isset($json_api_response['message']))) {
    22             return '{"type":"' . $type . '", "ErrorMessages":["' . "(" . sanitize_text_field($json_api_response['ErrorCode']) . ") " . sanitize_text_field( $json_api_response['Messages'][0] ) . '"] , "console":"' . $stage . '"}';
     23        if (isset($json_api_response['ErrorCode']) && (isset($json_api_response['Messages']) || isset($json_api_response['message']))) {
     24            return '{"type":"' . $type . '", "ErrorMessages":["' . "(" . sanitize_text_field($json_api_response['ErrorCode']) . ") " . sanitize_text_field($json_api_response['Messages'][0]) . '"] , "console":"' . $stage . '"}';
    2325        }
    2426
    2527        return '{"type":"' . $type . '", "ErrorMessages":["Internal Error has occurred."] , "console":"' . $stage . '"}';
    2628    }
    27    
     29
    2830    /**
    2931     * Logs to the options page errors that come through
    3032     */
    31     public function log_error( $response ) {
    32         $current_log = get_option( 'pay_advantage_error_logging' );
    33         if ( $current_log == 0 ) {
    34             $current_log =  gmdate( 'Y-m-d\TH:i:s\Z' ) . ': ' . sanitize_text_field( $response ) . '&#13;&#10;';
     33    public function log_error($response)
     34    {
     35        $current_log = get_option('pay_advantage_error_logging');
     36        if ($current_log == 0) {
     37            $current_log =  gmdate('Y-m-d\TH:i:s\Z') . ': ' . sanitize_text_field($response) . '&#13;&#10;';
    3538        } else {
    36             $current_log = gmdate('Y-m-d\TH:i:s\Z') . ': ' . sanitize_text_field( $response ) . '&#13;&#10;' . sanitize_text_field( $current_log );
     39            $current_log = gmdate('Y-m-d\TH:i:s\Z') . ': ' . sanitize_text_field($response) . '&#13;&#10;' . sanitize_text_field($current_log);
    3740        }
    38        
    39         if ( strlen( $current_log ) > PAYADV_MAX_LOG_SIZE_CHARS ) {
    40             $current_log = substr( $current_log , 0, PAYADV_MAX_LOG_SIZE_CHARS );
     41
     42        if (strlen($current_log) > PAYADV_MAX_LOG_SIZE_CHARS) {
     43            $current_log = substr($current_log, 0, PAYADV_MAX_LOG_SIZE_CHARS);
    4144        }
    42         update_option( 'pay_advantage_error_logging', $current_log );
     45        update_option('pay_advantage_error_logging', $current_log);
    4346    }
    4447}
    45 
    46 ?>
  • pay-advantage/trunk/shared/payadvantage-auth.php

    r2040227 r2094189  
    1212        $username = sanitize_user( get_option( 'pay_advantage_user_name' ) );
    1313        $password = wp_strip_all_tags ( get_option( 'pay_advantage_password' ) );
    14         return '{
    15         "grant_type" :"password",
    16         "username" :"'.$username.'",
    17         "password" :"'.$password.'"
    18         }';
     14        return array(
     15            "username" => $username,
     16            "password" => $password
     17        );
    1918    }
    2019
     
    2221     * Used to get auth token from the server.
    2322     */
    24     public function get_auth_token( $auth_data )
     23    public function get_auth_token( $auth_data, $url )
    2524    {
    2625        $result_processor = new Pay_Advantage_Result_Processor();
     
    3029        }
    3130
    32         $url = PAYADV_API_URL . '/token';
     31        $auth["appId"] = PAYADV_APP_ID;
     32
     33        if(empty($url)) {
     34            $url = get_option('pay_advantage_url');
     35        }
     36
     37        $url .= '/app-token';
    3338        $data = array(
    3439            'headers' => array(
     
    3641                'Expect' => ''
    3742            ),
    38             'body' => $auth
     43            'body' => json_encode($auth)
    3944        );
    4045        $response = wp_remote_post( $url, $data );       
Note: See TracChangeset for help on using the changeset viewer.