Plugin Directory

Changeset 2574918


Ignore:
Timestamp:
07/29/2021 06:21:25 PM (4 years ago)
Author:
yuriykipnis
Message:

Migrate to V2
Fix merchant parameter in the session request
Fix invalid payment
Dynamic support for brand

Location:
consumer-financing-by-chargeafter/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • consumer-financing-by-chargeafter/trunk/assets/js/promo.js

    r2428921 r2574918  
    1 !function(e,t,c,a,n){var r,o=t.getElementsByTagName(c)[0];e.ChargeAfter || (e.ChargeAfter = {}), t.getElementById(a)||(e.ChargeAfter.cfg = n,(r=t.createElement(c)).id=a, r.src="https://cdn" + caConfig.url + "/promotional-widget/v1/widget.min.js?t="+1*new Date, r.async=!0,o.parentNode.insertBefore(r,o))}(window,document,"script","chargeafter-promotional-widget",caConfig);
     1!function(e,t,c,a,n){var r,o=t.getElementsByTagName(c)[0];e.ChargeAfter || (e.ChargeAfter = {}), t.getElementById(a)||(e.ChargeAfter.cfg = n,(r=t.createElement(c)).id=a, r.src="https://cdn" + caConfig.url + "/promotional-widget/v2/widget.min.js?t="+1*new Date, r.async=!0,o.parentNode.insertBefore(r,o))}(window,document,"script","chargeafter-promotional-widget",caConfig);
    22jQuery(".single_variation_wrap").on("show_variation",function(i,e){let t=e.display_price,a=jQuery(".ca-promotional-widget.ca-product");if(t&&a){let i=a.data("widget-item-price"),e=a.data("widget-item-sku");t!=i&&e&&(ChargeAfter.promotionalWidget.update({items:[{sku:e,price:t}]}),a.data("widget-item-price",t))}});
  • consumer-financing-by-chargeafter/trunk/includes/wc-chargeafter-api.php

    r2556894 r2574918  
    1818     */
    1919    public static function api_get_charge_data( $charge_id ) {
    20         $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v1/post-sale/charges/' . (string) $charge_id;
     20        $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v2/post-sale/charges/' . (string) $charge_id;
    2121
    2222        return self::api_generic_post_sale( 'wp_safe_remote_get', $url );
     
    8181     */
    8282    public static function api_post_sale( $charge_id, $action, $data = '' ) {
    83         $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v1/post-sale/charges/' . (string) $charge_id . '/' . $action;
     83        $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v2/post-sale/charges/' . (string) $charge_id . '/' . $action;
    8484
    8585        return self::api_generic_post_sale( 'wp_safe_remote_post', $url, $data );
     
    132132     */
    133133    public static function api_create_charge( $token ) {
    134         $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v1/payment/charges';
     134        $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v2/payment/charges';
    135135
    136136        return self::api_generic_post_sale( 'wp_safe_remote_post', $url, json_encode( array( 'confirmationToken' => $token ) ) );
     
    146146     */
    147147    public static function api_payment_partially_update( $chargeId, $order_id ) {
    148         $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v1/post-sale/charges/' . $chargeId;
     148        $url = self::get_api_prefix() . WC_ChargeAfter_Helper::get_url_suffix() . '/v2/post-sale/charges/' . $chargeId;
    149149
    150150        return self::api_generic_patch_sale( $url, json_encode( array( 'merchantOrderId' => (string) $order_id ) ) );
     
    195195                'requestInfo' => [
    196196                    'flowType' => 'Apply',
    197                     'channel' => 'InStore',
     197                    'channel' => 'e_commerce',
    198198                    'source' => 'Api'
    199199                ]
     
    237237        $body = json_decode($body, true);
    238238
    239         return key_exists('data', $body) && isset($body['data']['MerchantId']) ? $body['data']['MerchantId'] : null;
     239        return key_exists('data', $body) && isset($body['data']['merchantId']) ? $body['data']['merchantId'] : null;
    240240    }
    241241
     
    249249    public static function api_get_merchant_settings( $merchant_id ) {
    250250        $json = @file_get_contents(WC_ChargeAfter_Helper::get_merchant_settings_with_cdn($merchant_id));
    251         if (empty($json)) {
    252             return null;
    253         }
    254 
    255         return json_decode($json, true);
     251        if (!empty($json)) {
     252            $json_settings = json_decode($json, true);
     253            if (empty($json_settings)) {
     254                $json_settings = json_decode(gzdecode($json), true);
     255            }
     256
     257            return $json_settings;
     258        }
     259
     260        return null;
    256261    }
    257262}
  • consumer-financing-by-chargeafter/trunk/includes/wc-chargeafter-helper.php

    r2556894 r2574918  
    343343     */
    344344    public static function get_cdn_url() {
    345         return 'https://storage.googleapis.com/cdn-production-bucket/';
     345        return self::is_sandbox()
     346                ? 'https://cdn-sandbox.ca-dev.co/'
     347                : 'https://storage.googleapis.com/cdn-production-bucket/';
    346348    }
    347349
  • consumer-financing-by-chargeafter/trunk/includes/wc-chargeafter-start-checkout-script.php

    r2556894 r2574918  
    164164     */
    165165    public static function start_checkout_script( $public_key, $url_suffix ) {
    166         $date = '${Date.now()}';
    167 
    168166        $onDataUpdate = '';
    169167        if ( WC_ChargeAfter_Helper::is_enabled_data_update() ) {
     
    197195                };
    198196               
    199                 document.addEventListener('DOMContentLoaded', () => {   
    200                     (function () {
    201                         var script = document.getElementById('ca-integration-script') || document.createElement('script');
    202                         script.src = `https://cdn{{URL_SUFFIX}}/web/v1/caIntegration.min.js?t={$date}`;
    203                         script.id = 'ca-integration-script';
    204                         document.body.append(script);
    205                     })();
    206                 });
     197                !function(e,t,c,a,n){var r,o=t.getElementsByTagName(c)[0];
     198                e.ChargeAfter || (e.ChargeAfter = {}),
     199                t.getElementById(a)||(e.ChargeAfter.cfg = n,(r=t.createElement(c)).id=a,
     200                r.src='https://cdn{{URL_SUFFIX}}/web/v2/chargeafter.min.js?t='+1*new Date,
     201                r.async=!0,o.parentNode.insertBefore(r,o))}
     202                (window,document,'script','chargeafter-checkout-finance',caConfig);
    207203               
    208204                var presentCheckout = function(hash) {
Note: See TracChangeset for help on using the changeset viewer.