Changeset 2800366
- Timestamp:
- 10/18/2022 05:46:11 AM (3 years ago)
- Location:
- chaiport-payment/trunk
- Files:
-
- 2 edited
-
chaiportGateway.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
chaiport-payment/trunk/chaiportGateway.php
r2721674 r2800366 4 4 * Plugin URI: https://www.docs.chaiport.io/plugins_and_sdks/woocommerce-plugin.html 5 5 * Description: Single Payment 6 * Version: 1.0. 46 * Version: 1.0.5 7 7 * Requires at least: 5.6 8 8 * Author: Chai Finance … … 97 97 $orderId = $order->get_id(); 98 98 99 $chaiPortId = get_bloginfo('name') . "-MERCHANT-" . $orderId;100 99 $options = get_option('woocommerce_chaiport_settings'); 101 100 $chaiApiUrl = "https://api.chaiport.io/api/getTransactionStatus/"; 102 101 $publicKey = $options["publishable_key"]; 103 102 $privateKey = $options["private_key"]; 103 $chaiPortId = $publicKey . "-MERCHANT-" . $orderId; 104 104 $orderStatusType = $options["payment_process_action"]; 105 105 $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 106 124 $header = array( 107 125 'headers' => array( 108 ' signature' => ChaiportGenerateFetchStatusSignature($chaiPortId, $privateKey),109 ' publicKey' => $publicKey126 'X-Chaipay-Client-Key' => $publicKey, 127 'Authorization' => "Bearer " . $token 110 128 ) 111 129 ); … … 669 687 $environment = $this->testmode ? "sandbox" : "live"; 670 688 671 $merchantOrder = get_bloginfo('name'). "-MERCHANT-" . $order->get_id();689 $merchantOrder = $publicKey . "-MERCHANT-" . $order->get_id(); 672 690 673 691 $order->add_order_note("Chaiport OrderId: $merchantOrder"); … … 692 710 $itemsArray = array(); 693 711 // Get and Loop Over Order Items 712 $discount_total = 0; 694 713 foreach ($order->get_items() as $item_id => $item) { 695 714 $order_item_id = $item->get_id(); … … 705 724 "image" => $image_url, 706 725 ); 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 } 707 730 array_push($itemsArray, $temp); 708 731 } … … 712 735 713 736 $merchantObj = array( 714 "name" => "Blog",737 "name" => get_bloginfo('name'), 715 738 "logo" => $image[0], 716 739 "back_url" => get_bloginfo('url') . "/checkout/", 717 740 "shipping_charges" => (float)$order->get_shipping_total(), 718 "promo_discount" => 0741 "promo_discount" => $discount_total 719 742 ); 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 } 720 769 721 770 $billingShippingArray = $this->getBillingShippingInfo($order); … … 728 777 "amount" => (float)$amount, 729 778 "currency" => "$currencyCode", 730 "description" => " -",779 "description" => "Your order-id is: $merchantOrder", 731 780 "order_details" => $itemsArray, 732 781 "billing_details" => $billingShippingArray[0], … … 734 783 "success_url" => "$red", 735 784 "failure_url" => "$red", 736 "country_code" => $ order->get_billing_country(),737 "expiry_hours" => 1,785 "country_code" => $countryCode, 786 "expiry_hours" => 96, 738 787 "is_checkout_embed" => true, 739 788 "show_shipping_details" => $this->getOptionBool('show_shipping_details'), -
chaiport-payment/trunk/readme.txt
r2721677 r2800366 3 3 Tags: chaipay, chaiport, payments, woocommerce, ecommerce 4 4 Requires at least: 3.9.2 5 Tested up to: 5.8.16 Stable tag: 1.0. 45 Tested up to: 6.0.2 6 Stable tag: 1.0.5 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.