Plugin Directory

Changeset 2800366


Ignore:
Timestamp:
10/18/2022 05:46:11 AM (3 years ago)
Author:
chaifinport
Message:

fixing redirection issue and addiing discount login

Location:
chaiport-payment/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • chaiport-payment/trunk/chaiportGateway.php

    r2721674 r2800366  
    44 * Plugin URI:        https://www.docs.chaiport.io/plugins_and_sdks/woocommerce-plugin.html
    55 * Description:       Single Payment
    6  * Version:           1.0.4
     6 * Version:           1.0.5
    77 * Requires at least: 5.6
    88 * Author:            Chai Finance
     
    9797        $orderId = $order->get_id();
    9898
    99         $chaiPortId = get_bloginfo('name') . "-MERCHANT-" . $orderId;
    10099        $options = get_option('woocommerce_chaiport_settings');
    101100        $chaiApiUrl = "https://api.chaiport.io/api/getTransactionStatus/";
    102101        $publicKey = $options["publishable_key"];
    103102        $privateKey = $options["private_key"];
     103        $chaiPortId = $publicKey . "-MERCHANT-" . $orderId;
    104104        $orderStatusType = $options["payment_process_action"];
    105105        $getOrderStatusUrl = $chaiApiUrl . $chaiPortId;
     106
     107        // Create token header as a JSON string
     108        $jwt_header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']);
     109        $encodeData = array(
     110            "iss" => "CHAIPAY",
     111            "sub" => $publicKey,
     112            "iat" => time(),
     113            "exp" => time() + 100
     114        );
     115        $payload = json_encode($encodeData);
     116
     117        $base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($jwt_header));
     118        $base64UrlPayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload));
     119        $signature = hash_hmac('sha256', $base64UrlHeader . "." . $base64UrlPayload, $privateKey, true);
     120        $base64UrlSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));
     121        // Create JWT
     122        $token = $base64UrlHeader . "." . $base64UrlPayload . "." . $base64UrlSignature;
     123
    106124        $header = array(
    107125            'headers' => array(
    108                 'signature' => ChaiportGenerateFetchStatusSignature($chaiPortId, $privateKey),
    109                 'publicKey' => $publicKey
     126                'X-Chaipay-Client-Key' => $publicKey,
     127                'Authorization' => "Bearer " . $token
    110128            )
    111129        );
     
    669687            $environment = $this->testmode ? "sandbox" : "live";
    670688
    671             $merchantOrder = get_bloginfo('name') . "-MERCHANT-" . $order->get_id();
     689            $merchantOrder = $publicKey . "-MERCHANT-" . $order->get_id();
    672690
    673691            $order->add_order_note("Chaiport OrderId: $merchantOrder");
     
    692710            $itemsArray = array();
    693711            // Get and Loop Over Order Items
     712            $discount_total = 0;
    694713            foreach ($order->get_items() as $item_id => $item) {
    695714                $order_item_id = $item->get_id();
     
    705724                    "image" => $image_url,
    706725                );
     726                if ( $product->is_on_sale() ) {
     727                    $discount = ((float)$product->get_regular_price() - (float)$product->get_sale_price()) * (int)$item->get_quantity();
     728                    $discount_total += $discount;
     729                }
    707730                array_push($itemsArray, $temp);
    708731            }
     
    712735
    713736            $merchantObj = array(
    714                 "name" => "Blog",
     737                "name" => get_bloginfo('name'),
    715738                "logo" => $image[0],
    716739                "back_url" => get_bloginfo('url') . "/checkout/",
    717740                "shipping_charges" => (float)$order->get_shipping_total(),
    718                 "promo_discount" => 0
     741                "promo_discount" => $discount_total
    719742            );
     743
     744            $countryCode = $order->get_billing_country();
     745            if (strlen($countryCode) == 0) {
     746                $countryCode = $order->get_shipping_country();
     747            }
     748            if (strlen($countryCode) == 0) {
     749                if ($currencyCode == "VND") {
     750                    $countryCode = "VN";
     751                } else if ($currencyCode == "THB") {
     752                    $countryCode = "TH";
     753                } else if ($currencyCode == "IDR") {
     754                    $countryCode = "ID";
     755                } else if ($currencyCode == "MYR") {
     756                    $countryCode = "MY";
     757                } else if ($currencyCode == "SGD") {
     758                    $countryCode = "SG";
     759                } else if ($currencyCode == "PHP") {
     760                    $countryCode = "PH";
     761                } else if ($currencyCode == "TWD") {
     762                    $countryCode = "TW";
     763                } else if ($currencyCode == "KRW") {
     764                    $countryCode = "KR";
     765                } else if ($currencyCode == "USD") {
     766                    $countryCode = "US";
     767                }
     768            }
    720769
    721770            $billingShippingArray = $this->getBillingShippingInfo($order);
     
    728777                "amount" => (float)$amount,
    729778                "currency" => "$currencyCode",
    730                 "description" => "-",
     779                "description" => "Your order-id is: $merchantOrder",
    731780                "order_details" => $itemsArray,
    732781                "billing_details" => $billingShippingArray[0],
     
    734783                "success_url" => "$red",
    735784                "failure_url" => "$red",
    736                 "country_code" => $order->get_billing_country(),
    737                 "expiry_hours" => 1,
     785                "country_code" => $countryCode,
     786                "expiry_hours" => 96,
    738787                "is_checkout_embed" => true,
    739788                "show_shipping_details" => $this->getOptionBool('show_shipping_details'),
  • chaiport-payment/trunk/readme.txt

    r2721677 r2800366  
    33Tags: chaipay, chaiport, payments, woocommerce, ecommerce
    44Requires at least: 3.9.2
    5 Tested up to: 5.8.1
    6 Stable tag: 1.0.4
     5Tested up to: 6.0.2
     6Stable tag: 1.0.5
    77Requires PHP: 5.6
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.