Changeset 3152740
- Timestamp:
- 09/16/2024 02:10:42 PM (19 months ago)
- Location:
- paylink/trunk
- Files:
-
- 4 edited
-
languages/paylink-ar.mo (modified) (previous)
-
languages/paylink-ar.po (modified) (1 diff)
-
paylink.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
paylink/trunk/languages/paylink-ar.po
r2433993 r3152740 1 1 msgid "" 2 2 msgstr "" 3 "Project-Id-Version: \n"3 "Project-Id-Version: Paylink Payment Gateway\n" 4 4 "POT-Creation-Date: \n" 5 5 "PO-Revision-Date: \n" 6 6 "Last-Translator: \n" 7 "Language-Team: \n" 7 "Language-Team: Paylink Co\n" 8 "Language: ar\n" 8 9 "MIME-Version: 1.0\n" 9 10 "Content-Type: text/plain; charset=UTF-8\n" 10 11 "Content-Transfer-Encoding: 8bit\n" 11 " Language: ar\n"12 "X-Generator: Poedit 2.4.1\n"12 "Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);\n" 13 "X-Generator: Poedit 3.4.2\n" 13 14 14 msgid " Paylink"15 msgstr " بيلينك"15 msgid "APP ID" 16 msgstr "معرف التطبيق (App Id)" 16 17 17 msgid " <span style='color:red;font-weight: bold'>You are using the testing environment</span>. Please use the testing credentials, <b>APP ID: APP_ID_1123453311</b>, <b>Secret Key: 0662abb5-13c7-38ab-cd12-236e58f43766</b>"18 msgstr " <span style='color:red;font-weight: bold'>انت تستخدم بيئة الاختبار</span>. الرجاء استخدام المفاتيح التالية, <b>APP ID: APP_ID_1123453311</b>, <b>Secret Key: 0662abb5-13c7-38ab-cd12-236e58f43766</b>"18 msgid "Callback URL" 19 msgstr "Callback Url" 19 20 20 msgid " Environment"21 msgstr "ب يئة النظام"21 msgid "Card Brands" 22 msgstr "بطاقات الدفع المتاحة" 22 23 23 msgid " Testing Environment"24 msgstr " بيئة الاختبار"24 msgid "Description" 25 msgstr "وصف بوابة الدفع" 25 26 26 msgid " Production Environment"27 msgstr " البيئة الحية"27 msgid "Display Thank you page" 28 msgstr "عرض صفحة الشكر" 28 29 29 msgid " Online Payment Gateway"30 msgstr " بوابة دفع الكتروني"30 msgid "Display a Thank you page before redirecting to the Paylink payment page." 31 msgstr "عرض صفحة الشكر قبل توجيه المستخدم إلى صفحة الدفع Paylink." 31 32 32 msgid "Is it a testing environment" 33 msgstr "هل هي بيئة اختبار" 33 msgid "Empty response received from Paylink API while adding invoice." 34 msgstr "تم استلام استجابة فارغة من Paylink أثناء إضافة الفاتورة." 35 36 msgid "Empty response received from Paylink API while authenticating." 37 msgstr "تم استلام استجابة فارغة من Paylink أثناء المصادقة." 38 39 msgid "Empty response received from Paylink API while getting invoice." 40 msgstr "تم استلام استجابة فارغة من Paylink أثناء استيراد معلومات الفاتورة." 41 42 msgid "Enable/Disable" 43 msgstr "تمكين/تعطيل" 44 45 msgid "Enable Paylink Payment Gateway" 46 msgstr "تمكين بوابة الدفع Paylink" 47 48 msgid "Enable Test Mode" 49 msgstr "تمكين وضع الاختبار" 50 51 msgid "Error:" 52 msgstr "خطأ:" 53 54 msgid "Failed Payment Message" 55 msgstr "رسالة فشل عملية الدفع" 56 57 msgid "Failed to add invoice to Paylink API. Status Code:" 58 msgstr "فشلت عملية إرسال الفاتورة إلى نظام Paylink. رمز الحالة:" 59 60 msgid "Failed to authenticate with Paylink API. Status Code:" 61 msgstr "يوجد خطأ في مفاتيح الربط مع Paylink. رمز الحالة:" 62 63 msgid "Failed to authenticate with the Paylink API!" 64 msgstr "يوجد خطأ في مفاتيح الربط مع Paylink!" 65 66 msgid "Failed to connect to the Paylink API. Please try again later." 67 msgstr "فشل الاتصال بـ Paylink API. يرجى المحاولة مرة أخرى في وقت لاحق." 68 69 msgid "Failed to get invoice from Paylink API. Status Code:" 70 msgstr "فشلت عملية استيراد معلومات الفاتورة من Paylink. رمز الحالة:" 71 72 msgid "Instructions" 73 msgstr "رسالة التحويل لبوابة الدفع" 74 75 msgid "Instructions that will be added to the thank you page." 76 msgstr "سوف يتم عرض هذه الرسالة قبل تحويل العميل إلى صفحة الدفع في Paylink." 77 78 msgid "No URL found in the Paylink API response" 79 msgstr "لم يتم العثور على عنوان URL في بيانات الفاتورة المستوردة من Paylink API" 80 81 msgid "No authentication token found in the response from Paylink API." 82 msgstr "لم يتم العثور على رمز مصادقة في الاستجابة من Paylink API." 83 84 msgid "No order ID found in the request!" 85 msgstr "لم يتم العثور على معرف الطلب (Order ID)!" 86 87 msgid "No order status found in the Paylink API response" 88 msgstr "لم يتم العثور على حالة الطلب (order status) في معلومات الطلب المستوردة من Paylink API" 89 90 msgid "No transaction number found in the request!" 91 msgstr "لم يتم العثور على رقم المعاملة في الطلب!" 92 93 msgid "Order ID is missing!" 94 msgstr "معرف الطلب مفقود!" 95 96 msgid "Order not found!" 97 msgstr "الطلب غير موجود!" 34 98 35 99 msgid "Paylink Payment Gateway" 36 100 msgstr "بوابة الدفع Paylink" 37 101 38 msgid "Pay Using PayLink"39 msgstr " الدفع باستخدام PayLink"102 msgid "Paylink Transaction Number" 103 msgstr "رقم معاملة Paylink" 40 104 41 msgid "Pay by Mada, VISA, Mastercard, or ApplePay"42 msgstr " ادفع بواسطة بطاقة مدى، فيزا، ماستركارد، او أبل با"105 msgid "Paylink payment gateway for WooCommerce, It provides your customers with the popular payment methods in the Kingdom of Saudi Arabia, such as" 106 msgstr "بوابة الدفع Paylink لـ WooCommerce، توفر لعملائك طرق الدفع الشائعة في المملكة العربية السعودية، مثل" 43 107 44 msgid " It provides your customers with the popular payment methods in the Kingdom of Saudi Arabia, such as Mada, Visa, MasterCard, and Apple Pay"45 msgstr " يوفر لعملائك وسائل الدفع الشائعة في المملكة العربية السعودية مثل مدى، فيزا، ماستركارد،و ابل باي"108 msgid "Payment not completed yet!" 109 msgstr "لم يتم إكمال الدفع بعد!" 46 110 47 msgid " Support Email"48 msgstr " البريد الإلكتروني للدعم"111 msgid "Place the payment gateway in test mode." 112 msgstr "وضع بوابة الدفع في وضع الاختبار." 49 113 50 msgid " APP ID"51 msgstr "مع رف التطبيق (APP ID)"114 msgid "Seamless transactions with popular payment methods in the Kingdom of Saudi Arabia, including:" 115 msgstr "معاملات سلسة باستخدام طرق الدفع الشائعة في المملكة العربية السعودية، بما في ذلك:" 52 116 53 117 msgid "Secret Key" 54 118 msgstr "المفتاح السري (Secret Key)" 55 119 56 msgid " Support email"57 msgstr " البريد الإلكتروني للدعم"120 msgid "Test Mode" 121 msgstr "وضع الاختبار" 58 122 59 msgid "Successful Payment Message" 60 msgstr "رسالة الدفع الناجحة" 61 62 msgid "Failed Payment Message" 63 msgstr "رسالة الدفع الفاشلة" 64 65 msgid "Thank you for your order, please click the button below to pay with PayLink." 66 msgstr "شكرًا لك على طلبك ، الرجاء النقر فوق الزر أدناه للدفع باستخدام بيلينك." 123 msgid "Test Mode is enabled." 124 msgstr "تم تمكين وضع الاختبار." 67 125 68 126 msgid "Thank you for your order, you will be redirected to Paylink payment page." 69 msgstr "شكرًا ل ك على طلبك ، سيتم توجيهك الى صفحة دفع بيلينك الان."127 msgstr "شكرًا لطلبك، سيتم توجيهك إلى صفحة الدفع Paylink." 70 128 71 msgid "Something error. Please try again by refreshing the page" 72 msgstr "خطأ ما. يرجى المحاولة مرة أخرى عن طريق تحديث الصفحة" 129 msgid "Thank you for your order. Please complete your payment using the payment button below." 130 msgstr "شكرًا لطلبك. يرجى إكمال الدفع باستخدام زر الدفع أدناه." 131 132 msgid "The card brands to use for the payment. Separate the brands with a comma. Valid brands are:" 133 msgstr "بطاقات الدفع المسموح بها، افصل بين العلامات بفاصلة. القيم المتاحة هي:" 134 135 msgid "This controls the description which the user sees during checkout." 136 msgstr "يتحكم هذا في الوصف الذي يراه المستخدم أثناء الدفع." 137 138 msgid "This controls the error message that appears to the user if the payment fails." 139 msgstr "يتحكم هذا في رسالة الخطأ التي تظهر للمستخدم إذا فشل الدفع." 140 141 msgid "This controls the title which the user sees during checkout." 142 msgstr "يتحكم هذا في العنوان الذي يراه المستخدم أثناء الدفع." 143 144 msgid "This is the APP ID provided by Paylink." 145 msgstr "هذا هو معرف التطبيق المقدم من Paylink." 146 147 msgid "This is the URL where Paylink will send the payment status callback." 148 msgstr "هذا هو العنوان URL الذي سترسل Paylink إليه استدعاء حالة الدفع." 149 150 msgid "This is the secret key provided by Paylink." 151 msgstr "هذا هو المفتاح السري المقدم من Paylink." 152 153 msgid "Title" 154 msgstr "اسم وسيلة الدفع" 155 156 msgid "Transaction number is missing!" 157 msgstr "رقم المعاملة مفقود!" 158 159 msgid "Unable to send authentication request: API ID or secret key is missing. Please provide the required credentials to proceed." 160 msgstr "تعذر إرسال طلب المصادقة: (App ID) أو (Secret Key) مفقود. يرجى توفير بيانات الاعتماد المطلوبة للمتابعة." 161 162 msgid "Visa/Mastercard" 163 msgstr "فيزا/ماستركارد" 164 165 msgid "WC Payment Gateway class does not exist. WooCommerce is not installed." 166 msgstr "لم يتم تثبيت إضافة WooCommerce. يجب أن يتم تثبيت الإضافة لتتمكن من استخدام بوابة الدفع بالشكل الصحيح." 167 168 msgid "WooCommerce is not installed." 169 msgstr "لم يتم تثبيت إضافة WooCommerce. يجب أن يتم تثبيت الإضافة لتتمكن من استخدام بوابة الدفع بالشكل الصحيح." 170 171 msgid "Your payment has failed, please try again." 172 msgstr "فشلت عملية الدفع الخاصة بك، يرجى المحاولة مرة أخرى." 173 174 msgid "amex" 175 msgstr "أمريكان إكسبريس" 176 177 msgid "mada" 178 msgstr "مدى" 179 180 msgid "stcpay" 181 msgstr "STC Pay" 182 183 msgid "tabby" 184 msgstr "تابي" 185 186 msgid "tamara" 187 msgstr "تمارا" 188 189 msgid "urpay" 190 msgstr "urPay" -
paylink/trunk/paylink.php
r2921651 r3152740 1 <?php /** @noinspection DuplicatedCode */ 1 <?php 2 3 /** @noinspection ALL */ 4 5 /** @noinspection DuplicatedCode */ 6 2 7 /** 3 * Plugin Name: Paylink 8 * Plugin Name: Paylink Payment Gateway 9 * Plugin URI: https://paylink.sa 10 * Author: Paylink Co 11 * Author URI: https://paylink.sa 4 12 * Description: Use this woocommerce payment gateway plugin to enable clients of your store to pay using Paylink gateway. 5 * Version: 2.02 6 * Author: Paylink Co 13 * Version: 3.0.4 14 * License: GPL-2.0+ 15 * License URL: http://www.gnu.org/licenses/gpl-2.0.txt 7 16 * text-domain: paylink 8 * Plugin URI: https://paylink.sa9 17 * Domain Path: /languages 18 * 19 * Class WC_Gateway_Paylink file. 20 * 21 * @package WooCommerce\Paylink 10 22 */ 11 23 12 add_action('plugins_loaded', 'init_PayLinkAPI', 0); 24 // If this file is called directly, abort. 25 if (!defined('ABSPATH')) { 26 exit; // Exit if accessed directly. 27 } 13 28 14 function init_PayLinkAPI() 29 // Check if WooCommerce is installed 30 if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 31 notice_error('WooCommerce is not installed.'); 32 return; 33 } 34 35 // Add a custom payment gateway 36 add_action('plugins_loaded', 'init_paylink_gateway', 11); 37 add_filter('woocommerce_payment_gateways', 'add_paylink_gateway'); 38 39 // Initialize the gateway 40 function init_paylink_gateway() 15 41 { 16 if (!defined('ABSPATH')) { 17 exit; // Exit if accessed directly. 18 } 42 // If the class WC_Payment_Gateway doesn't exist, it means WooCommerce is not installed. 43 if (!class_exists('WC_Payment_Gateway')) { 44 notice_error('WC Payment Gateway class does not exist. WooCommerce is not installed.'); 45 return; 46 } 19 47 20 // Register the Paylink payment gateway. 21 function paylinkwc_register_gateway($gateways) 22 { 23 $gateways[] = 'WcPayLink'; 24 return $gateways; 25 } 48 // Include the Paylink gateway class 49 require_once plugin_dir_path(__FILE__) . '/includes/class-wc-gateway-paylink.php'; 26 50 27 add_filter('woocommerce_payment_gateways', 'paylinkwc_register_gateway'); 51 add_action('woocommerce_thankyou', 'paylink_add_order_meta'); 52 add_action('woocommerce_order_details_after_order_table', 'paylink_display_order_reference', 10, 1); 28 53 29 // Add the Paylink order meta. 30 function paylinkwc_add_order_meta($order_id) 31 { 32 update_post_meta($order_id, '_paylink_transaction_no', $_GET['transactionNo']); 33 } 54 // Add the Paylink order meta. 55 function paylink_add_order_meta($order_id) 56 { 57 if (isset($_GET['transactionNo'])) { 58 update_post_meta($order_id, '_paylink_transaction_no', $_GET['transactionNo']); 59 } else { 60 update_post_meta($order_id, '_paylink_transaction_no', 'N/A'); 61 } 62 } 34 63 35 add_action('woocommerce_thankyou', 'paylinkwc_add_order_meta'); 64 // Display the Paylink order reference in the order details. 65 function paylink_display_order_reference($order) 66 { 67 $paylink_transaction_no = $order->get_meta('_paylink_transaction_no'); 68 if ($paylink_transaction_no) { 69 echo '<p><strong>Paylink Transaction Number:</strong> ' . $paylink_transaction_no . '</p>'; 70 } 71 } 72 } 36 73 37 // Display the Paylink order reference in the order details. 38 function paylinkwc_display_order_reference($order) 39 { 40 $paylink_transaction_no = $order->get_meta('_paylink_transaction_no'); 41 if ($paylink_transaction_no) { 42 echo '<p><strong>' . __('Paylink Transaction No', 'paylinkwc') . ':</strong> ' . $paylink_transaction_no . '</p>'; 43 } 44 } 74 // Add the gateway to WooCommerce 75 function add_paylink_gateway($methods) 76 { 77 $methods[] = 'WC_Gateway_Paylink'; 78 return $methods; 79 } 45 80 46 add_action('woocommerce_order_details_after_order_table', 'paylinkwc_display_order_reference'); 47 48 /** 49 * The main class representing the PaylinkWC payment gateway. 50 */ 51 class WcPayLink extends WC_Payment_Gateway 52 { 53 private $_token_auth; 54 private string $_get_invoice_url; 55 private string $_add_invoice_url; 56 private string $_login_url; 57 private string $_base_server_url; 58 private string $_is_testing; 59 60 private function postError($error, $calledUrl, $method) 61 { 62 try { 63 $apiId = $this->get_option('app_id'); 64 $apiKey = $this->get_option('secret_key'); 65 66 $post_parameter = [ 67 'error' => $error, 68 'calledUrl' => $calledUrl, 69 'apiId' => $apiId, 70 'apiKey' => $apiKey, 71 'method' => $method 72 ]; 73 wp_safe_remote_post('https://paylinkapp.paylink.sa/careapi/wp_log_error', [ 74 'headers' => [ 75 'Content-Type' => 'application/json', 76 ], 77 'body' => wp_json_encode($post_parameter), 78 ]); 79 } catch (Exception $ex) { 80 } 81 } 82 83 public function __construct() 84 { 85 load_plugin_textdomain('paylinkwc', false, 'paylink_wc_payment_gateway/languages'); 86 87 $this->id = 'paylinkwc'; 88 $this->icon = apply_filters('woocommerce_paylink_icon', 'https://paylink.sa/assets/img/paylink-logo.png'); 89 $this->has_fields = true; 90 $this->method_title = __('Paylink Payment Gateway', 'paylink'); 91 $this->method_description = __('It provides your customers with the popular payment methods in the Kingdom of Saudi Arabia, such as Mada, Visa, MasterCard, and Apple Pay', 'paylink'); 92 93 $this->supports = [ 94 'products', 95 'refunds' 96 ]; 97 98 $this->init_form_fields(); 99 $this->init_settings(); 100 101 $this->enabled = $this->get_option('enabled'); 102 $this->title = $this->get_option('title'); 103 $this->description = $this->get_option('description'); 104 105 $this->_is_testing = $this->get_option('is_testing_env'); 106 if ($this->_is_testing === 'on' || $this->_is_testing === 'yes') { 107 $this->_base_server_url = 'https://restpilot.paylink.sa'; 108 } else { 109 $this->_base_server_url = 'https://restapi.paylink.sa'; 110 } 111 $this->_get_invoice_url = $this->_base_server_url . '/api/getInvoice'; 112 $this->_login_url = $this->_base_server_url . '/api/auth'; 113 $this->_add_invoice_url = $this->_base_server_url . '/api/addInvoice'; 114 115 add_action('init', [$this, 'check_paylink_response']); 116 add_action('woocommerce_api_wc_paylink', [&$this, 'check_paylink_response']); 117 add_action('woocommerce_api_paylink', [&$this, 'check_paylink_response']); 118 add_action('woocommerce_api_' . strtolower(get_class($this)), [&$this, 'check_paylink_response']); 119 120 add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); 121 122 add_action('woocommerce_receipt_paylinkwc', [&$this, 'receipt_page']); 123 add_action('woocommerce_receipt_WC_paylinkwc', [&$this, 'receipt_page']); 124 125 add_action('wp_head', [&$this, 'write_order_payment_header']); 126 } 127 128 public function process_admin_options() 129 { 130 parent::process_admin_options(); 131 if ($this->settings['is_testing_env'] == 'yes' || $this->settings['is_testing_env'] == 'on') { 132 // $this->add_error(__("<span style='color:red;font-weight: bold'>You are using the testing environment</span>. Please use the testing credentials, <b>APP ID: APP_ID_1123453311</b>, <b>Secret Key: 0662abb5-13c7-38ab-cd12-236e58f43766</b>", 'paylink')); 133 $this->wc_add_notice(__("<span style='color:red;font-weight: bold'>You are using the testing environment</span>. Please use the testing credentials, <b>APP ID: APP_ID_1123453311</b>, <b>Secret Key: 0662abb5-13c7-38ab-cd12-236e58f43766</b>", 'paylink'), 'error'); 134 $this->display_errors(); 135 } 136 } 137 138 public function init_form_fields() 139 { 140 $this->form_fields = [ 141 'enabled' => [ 142 'title' => __('Enable/Disable', 'paylink'), 143 'type' => 'checkbox', 144 'label' => __('Enable Paylink payment', 'paylink'), 145 'default' => 'yes' 146 ], 147 'title' => [ 148 'title' => __('Title', 'paylink'), 149 'type' => 'text', 150 'description' => __('This controls the title which the user sees during checkout.', 'paylink'), 151 'default' => __('Pay with Paylink', 'paylink'), 152 'desc_tip' => true 153 ], 154 'description' => [ 155 'title' => __('Description', 'paylink'), 156 'type' => 'textarea', 157 'description' => __('This controls the description which the user sees during checkout.', 'paylink'), 158 'default' => __('Pay using Paylink', 'paylink'), 159 'desc_tip' => true 160 ], 161 'app_id' => [ 162 'title' => __('APP ID', 'paylink'), 163 'type' => 'text', 164 'description' => __('This is the APP ID assigned to you by Paylink.', 'paylink'), 165 'default' => '', 166 'desc_tip' => true, 167 'required' => true 168 ], 169 'secret_key' => [ 170 'title' => __('Secret Key', 'paylink'), 171 'type' => 'text', 172 'description' => __('This is the API Secret key assigned to you by Paylink.', 'paylink'), 173 'default' => '', 174 'desc_tip' => true, 175 'required' => true 176 ], 177 'callback_url' => [ 178 'title' => __('Callback URL', 'paylink'), 179 'type' => 'text', 180 'description' => __('This is the URL where Paylink will send the payment status callback.', 'paylink'), 181 // 'default' => get_site_url() . '/wc-api/paylinkwc/', 182 'default' => get_site_url() . '/wc-api/' . strtolower(get_class($this)), 183 'desc_tip' => true, 184 'custom_attributes' => [ 185 'readonly' => 'readonly' 186 ] 187 ], 188 // 'payment_form' => [ 189 // 'title' => __('Payment Form', 'paylink'), 190 // 'type' => 'select', 191 // 'description' => __('This controls the payment form which the user sees during checkout. On-Site will display payment in the same of the merchant website. The off-site fee will redirect income to Paylink payment pages.', 'paylink'), 192 // 'options' => [ 193 // 'onsite' => __('On Site', 'paylink'), 194 // 'offsite' => __('Off Site', 'paylink'), 195 // ], 196 // 'desc_tip' => true 197 // ], 198 'display_thank_you' => [ 199 'title' => __('Display Thank you page', 'paylink'), 200 'type' => 'select', 201 'description' => __('Display a Thank you page before redirecting to the Paylink payment page.', 'paylink'), 202 'options' => [ 203 'yes' => __('Yes', 'paylink'), 204 'no' => __('No', 'paylink'), 205 ], 206 'desc_tip' => true 207 ], 208 'is_testing_env' => [ 209 'title' => __('Environment', 'paylink'), 210 'type' => 'select', 211 'description' => __('This controls the payment gateway backend, either the production or testing environment.', 'paylink'), 212 'options' => [ 213 'yes' => __('Testing Environment', 'paylink'), 214 'no' => __('Production Environment', 'paylink'), 215 ], 216 'desc_tip' => true 217 ], 218 'fail_msg' => [ 219 'title' => __('Failed Payment Message', 'paylink'), 220 'description' => __('This controls the error message that appears to the user if the payment fails.', 'paylink'), 221 'type' => 'textarea', 222 'desc_tip' => true 223 ], 224 ]; 225 } 226 227 public function receipt_page($order_id) 228 { 229 $paymentForm = $this->get_option('payment_form'); 230 // if ($paymentForm == 'onsite') { 231 // wp_enqueue_script('paylinkwc', 'https://paylink.sa/assets/js/paylink.js', [], '1.0.0'); 232 // echo '<p>' . __('Thank you for your order', 'paylink') . $this->get_payment_button_html($order_id) . '</p>'; 233 // } else { 234 $url = $this->generate_paylink_url($order_id); 235 if ($url) { 236 $display_thank_you = $this->get_option('display_thank_you'); 237 238 if ($display_thank_you == 'no') { 239 wp_redirect($url); 240 exit; 241 } else { 242 echo '<p>' . __('Thank you for your order, you will be redirected to Paylink payment page.', 'paylink') . '</p>'; 243 echo "<script>setTimeout(function() {window.location.href = '" . $url . "';}, 2000);</script>"; 244 } 245 } else { 246 echo '<p>' . __('Something error. Please try again by refreshing the page', 'paylink') . '</p>'; 247 } 248 // } 249 } 250 251 private function generate_paylink_url($order_id) 252 { 253 $this->_token_auth = $this->login(); 254 if ($this->_token_auth) { 255 update_post_meta($order_id, 'login_token', $this->_token_auth); 256 return $this->createPaylinkInvoiceUrl($this->_token_auth, $order_id); 257 } else { 258 $this->postError(print_r($this->_token_auth, true), 'n/a', 'generate_paylink_url'); 259 return false; 260 } 261 } 262 263 private function createPaylinkInvoiceUrl($token, $order_id) 264 { 265 $order = wc_get_order($order_id); 266 // $callbackUrl = get_site_url() . '/wc-api/paylinkwc'; <-- this did not work. 267 268 $redirect_url = $order->get_checkout_order_received_url(); 269 if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) { 270 $redirect_url = add_query_arg('wc-api', strtolower(get_class($this)), $redirect_url); 271 } 272 273 $total = $order->get_total(); 274 $customerEmail = $order->get_billing_email(); 275 $note = ''; 276 $lang = 'ar'; 277 $customerName = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(); 278 $customerPhone = $order->get_billing_phone(); 279 280 $j_array = [ 281 'amount' => $total, 282 'orderNumber' => $order_id, 283 'callBackUrl' => $redirect_url, 284 'note' => $note, 285 'clientEmail' => $customerEmail, 286 'clientName' => $customerName, 287 'clientMobile' => $customerPhone, 288 'lang' => $lang, 289 'products' => [] 290 ]; 291 292 $json = wp_json_encode($j_array); 293 294 $parameter = [ 295 'body' => $json, 296 'headers' => [ 297 'Authorization' => 'Bearer ' . $token, 298 'Content-Type' => 'application/json' 299 ], 300 'timeout' => 60, 301 'httpversion' => '1.1', 302 'user-agent' => '1.0', 303 ]; 304 try { 305 $response = wp_safe_remote_post($this->_add_invoice_url, $parameter); 306 return json_decode($response['body'])->url; 307 } catch (Exception $exception) { 308 error_log(print_r($exception, true)); 309 $this->postError(print_r($exception, true), $this->_add_invoice_url, 'createPaylinkInvoiceUrl'); 310 return false; 311 } 312 } 313 314 private function login() 315 { 316 try { 317 $app_id = $this->get_option('app_id'); 318 $secret_key = $this->get_option('secret_key'); 319 320 $login_parameter = [ 321 'apiId' => $app_id, 322 'secretKey' => $secret_key, 323 'persistToken' => true 324 ]; 325 $login_response = wp_safe_remote_post($this->_login_url, [ 326 'headers' => [ 327 'Content-Type' => 'application/json', 328 ], 329 'body' => wp_json_encode($login_parameter), 330 ]); 331 $this->postError('logged in', $this->_login_url, 'login'); 332 $this->postError(print_r($login_response, true), $this->_login_url, 'login'); 333 return json_decode($login_response['body'])->id_token; 334 } catch (Exception $ex) { 335 error_log(print_r($ex, true)); 336 $this->postError(print_r($ex, true), $this->_login_url, 'login'); 337 return false; 338 } 339 } 340 341 public function process_payment($order_id) 342 { 343 // Get the order object 344 $order = wc_get_order($order_id); 345 346 // Add custom order notes 347 $order->add_order_note('Thank you for your order. Please complete your payment using the payment button below.'); 348 349 // Get the payment gateway URL 350 // $checkout_payment_url = $order->get_checkout_payment_url(true); 351 if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { 352 /* 2.1.0 */ 353 $checkout_payment_url = $order->get_checkout_payment_url(true); 354 } else { 355 /* 2.0.0 */ 356 $checkout_payment_url = get_permalink(get_option('woocommerce_pay_page_id')); 357 } 358 // Return the payment button HTML 359 return [ 360 'result' => 'success', 361 'redirect' => add_query_arg( 362 'order-pay', 363 $order->get_id(), 364 add_query_arg( 365 'key', 366 $order->get_order_key(), 367 $checkout_payment_url 368 ) 369 ) 370 ]; 371 } 372 373 public function check_paylink_response() 374 { 375 global $woocommerce; 376 $order_id = sanitize_text_field($_REQUEST['orderNumber']); 377 $transaction_no = sanitize_text_field($_REQUEST['transactionNo']); 378 379 $checkout_url = wc_get_checkout_url() . '&transactionNo=' . $transaction_no; 380 381 if (isset($order_id) && isset($transaction_no)) { 382 $order = wc_get_order($order_id); 383 384 $this->_token_auth = get_post_meta($order_id, 'token_auth'); 385 if (!$this->_token_auth) { 386 $this->_token_auth = $this->login(); 387 } 388 $options = [ 389 'headers' => [ 390 'Authorization' => 'Bearer ' . $this->_token_auth 391 ], 392 'timeout' => 60, 393 'httpversion' => '1.1', 394 'user-agent' => '1.0', 395 ]; 396 $response = wp_safe_remote_get($this->_get_invoice_url . '/' . $transaction_no, $options); 397 try { 398 $order_status = sanitize_text_field(json_decode($response['body'])->{'orderStatus'}); 399 $order_status = mb_convert_case($order_status, MB_CASE_LOWER, 'UTF-8'); 400 401 // validating order status value 402 if ($order_status == 'paid' || $order_status == 'completed') { 403 $checkout_url = $order->get_checkout_order_received_url() . '&transactionNo=' . $transaction_no; 404 $order->payment_complete($transaction_no); 405 $woocommerce->cart->empty_cart(); 406 } else { 407 $msg['class'] = 'error'; 408 $msg['message'] = $this->get_option('fail_msg'); 409 if (function_exists('wc_add_notice')) { 410 wc_add_notice($msg['message'], $msg['class']); 411 } else { 412 // $woocommerce->add_error(esc_html($msg['message'])); 413 $woocommerce->wc_add_notice($msg['message'], 'error'); 414 $woocommerce->set_messages(); 415 } 416 } 417 } catch (Exception $ex) { 418 error_log(print_r($ex, true)); 419 // $woocommerce->add_error('Internal Server Error. Try Again Please.'); 420 $woocommerce->wc_add_notice('Internal Server Error. Try Again Please.', 'error'); 421 $woocommerce->set_messages(); 422 } 423 } 424 wp_redirect($checkout_url); 425 // if (isset($_REQUEST['transactionNo'])) { 426 // $transaction_no = $_REQUEST['transactionNo']; 427 // $order_id = $_REQUEST['order_id']; 428 // $status = $_REQUEST['status']; 429 // 430 // $order = wc_get_order($order_id); 431 // 432 // if ($order) { 433 // if ($status == 'completed') { 434 // $order->update_status('processing'); 435 // } else { 436 // $order->update_status('failed'); 437 // } 438 // 439 // wc_reduce_stock_levels($order_id); 440 // wc_delete_product_transients(); 441 // 442 // $thankyou_page = $this->get_return_url($order); 443 // 444 // wc_get_template('checkout/thankyou.php', [ 445 // 'order' => $order, 446 // 'thankyou_page' => $thankyou_page 447 // ]); 448 // exit; 449 // } 450 // } 451 } 452 453 public function payment_fields() 454 { 455 if ($this->description) { 456 echo wpautop(wptexturize($this->description)); 457 } 458 } 459 460 public function write_order_payment_header() 461 { 462 if (!isset($_GET['key'])) { 463 return ''; 464 } 465 $key = $_GET['key']; 466 $order_id = wc_get_order_id_by_order_key($key); 467 $order = wc_get_order($order_id); 468 // $callbackUrl = get_site_url() . '/wc-api/paylinkwc'; 469 // $callbackUrl = get_site_url() . '/wc-api/' . strtolower(get_class($this)); 470 471 $callbackUrl = $order->get_checkout_order_received_url(); 472 if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) { 473 $callbackUrl = add_query_arg('wc-api', strtolower(get_class($this)), $callbackUrl); 474 } 475 476 $amount = $order->get_total(); 477 $orderNumber = $order_id; 478 $currency = $order->get_currency(); 479 480 $clientName = ''; 481 if ($order->get_billing_first_name() || $order->get_billing_last_name()) { 482 $clientName = ($order->get_billing_first_name() ?? ' ') . ' ' . ($order->get_billing_last_name() ?? ' '); 483 } elseif ($order->get_shipping_first_name() || $order->get_shipping_last_name()) { 484 $clientName = ($order->get_shipping_first_name() ?? ' ') . ' ' . ($order->get_shipping_last_name() ?? ' '); 485 } 486 487 $clientMobile = ''; 488 if ($order->get_billing_phone()) { 489 $clientMobile = $order->get_billing_phone(); 490 } elseif ($order->get_shipping_phone()) { 491 $clientMobile = $order->get_shipping_phone(); 492 } 493 494 $items = $order->get_items(); 495 $products = ''; 496 foreach ($items as $item) { 497 $product_id = $item->get_product_id(); 498 $product_name = $item->get_name(); 499 $product_quantity = $item->get_quantity(); 500 $product_total = $item->get_total(); 501 $products .= "{title: '$product_id - $product_name', price: $product_total, qty: $product_quantity},"; 502 } 503 504 $mode = $this->_is_testing == 'on' || $this->_is_testing == 'yes' ? 'test' : 'production'; 505 $token = $this->login(); 506 507 echo " 508 <script> 509 function submitPaylinkPayment() { 510 // paylink 511 let paylinkOrder = new Order({ 512 callBackUrl: '$callbackUrl', // callback page URL (for example http://localhost:6655 processPayment.php) in your site to be called after payment is processed. (mandatory) 513 clientName: '$clientName', // the name of the buyer. (mandatory) 514 clientMobile: '$clientMobile', // the mobile of the buyer. (mandatory) 515 amount: $amount, // the total amount of the order (including VAT or discount). (mandatory). NOTE: This amount is used regardless of total amount of products listed below. 516 currency: '$currency', 517 clientEmail: '$clientName', 518 orderNumber: '$orderNumber', // the order number in your system. (mandatory) 519 products: [ // list of products (optional) 520 $products 521 ], 522 }); 523 let payment = new PaylinkPayments({mode: '$mode', defaultLang: 'ar', backgroundColor: '#EEE'}); 524 payment.openPayment('$token', paylinkOrder); 525 } 526 527 function submitPaylinkApplePay() { 528 // paylink 529 let paylinkOrder = new Order({ 530 callBackUrl: '$callbackUrl', // callback page URL (for example http://localhost:6655 processPayment.php) in your site to be called after payment is processed. (mandatory) 531 clientName: '$clientName', // the name of the buyer. (mandatory) 532 clientMobile: '$clientMobile', // the mobile of the buyer. (mandatory) 533 amount: $amount, // the total amount of the order (including VAT or discount). (mandatory). NOTE: This amount is used regardless of total amount of products listed below. 534 currency: '$currency', 535 clientEmail: '$clientName', 536 orderNumber: '$orderNumber', // the order number in your system. (mandatory) 537 products: [ // list of products (optional) 538 $products 539 ], 540 }); 541 let payment = new PaylinkPayments({mode: '$mode', defaultLang: 'ar', backgroundColor: '#EEE'}); 542 payment.openApplePay('$token', paylinkOrder); 543 } 544 </script> 545 "; 546 } 547 548 private function get_payment_button_html($order_id) 549 { 550 $order = wc_get_order($order_id); 551 552 if ($order->get_status() == 'pending') { 553 554 $title = $this->get_option('title') ?? 'Pay'; 555 556 // Build the JavaScript code to be executed on the client side 557 $javascript_code = "<div> 558 <button onclick='submitPaylinkPayment()'>$title by Bank Card</button> 559 <button onclick='submitPaylinkApplePay()'>$title by ApplePay</button> 560 </div>"; 561 // Return the HTML for the payment button 562 return $javascript_code; 563 } 564 } 565 } 566 567 // Add the Paylink callback endpoint. 568 // function paylinkwc_add_callback_endpoint() 569 // { 570 // add_rewrite_endpoint('paylinkwc', EP_ROOT); 571 // } 572 // 573 // add_action('init', 'paylinkwc_add_callback_endpoint'); 574 // Handle the Paylink callback. 575 // function paylinkwc_handle_callback() 576 // { 577 // $gateway = new PaylinkWcGateway(); 578 // $gateway->process_callback(); 579 // } 580 // add_action('woocommerce_api_paylinkwc', 'paylinkwc_handle_callback'); 81 // Display an error notice 82 function notice_error(string $error) 83 { 84 echo '<div class="notice notice-error">'; 85 echo "<p>$error</p>"; 86 echo '</div>'; 581 87 } 582 // public function process_payment($order_id)583 // {584 // $order = wc_get_order($order_id);585 //586 // $params = [587 // 'app_id' => $this->get_option('app_id'),588 // 'secret_key' => $this->get_option('secret_key'),589 // 'amount' => $order->get_total(),590 // 'currency' => get_woocommerce_currency(),591 // 'order_id' => $order_id,592 // 'callback_url' => $this->get_option('callback_url'),593 // 'success_url' => $this->get_return_url($order),594 // 'cancel_url' => $order->get_cancel_order_url_raw()595 // ];596 //597 // $response = wp_remote_post('https://api.paylink.sa/api/v1/transactions', [598 // 'method' => 'POST',599 // 'headers' => [600 // 'Content-Type' => 'application/json'601 // ],602 // 'body' => json_encode($params),603 // 'timeout' => 60604 // ]);605 //606 // if (is_wp_error($response)) {607 // throw new Exception(__('An error occurred while processing your payment. Please try again.', 'paylinkwc'));608 // }609 //610 // $response_body = json_decode(wp_remote_retrieve_body($response));611 //612 // if ($response_body->success) {613 // return [614 // 'result' => 'success',615 // 'redirect' => $response_body->data->payment_url616 // ];617 // } else {618 // throw new Exception(__('An error occurred while processing your payment. Please try again.', 'paylinkwc'));619 // }620 // }621 -
paylink/trunk/readme.txt
r2921651 r3152740 1 === PayLink P lugin===2 Contributors: Paylink1 === PayLink Payment Gateway === 2 Contributors: hasanayoub, algarbisultan 3 3 Requires at least: 5.5.1 4 Tested up to: 6.2.2 5 Stable tag: 2.02 4 Tested up to: 6.6.2 5 Requires PHP: 7.0 6 Stable tag: 3.0.4 6 7 License: GPLv2 or later 7 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 9 10 == Description == 10 11 11 Paylink Payment Gateway 12 The PayLink Payment Gateway plugin allows you to accept popular payment methods in the Kingdom of Saudi Arabia, including mada, Visa/Mastercard, American Express, Tabby, Tamara, STC Pay, and URPay. 12 13 13 It provides your customers with the popular payment methods in the Kingdom of Saudi Arabia, such as Mada, Visa, MasterCard, and Apple Pay.14 For more information, visit [PayLink Developer Documentation](https://developer.paylink.sa/docs/woocommerce-plugin). 14 15 15 For more information, please visit https://developer.paylink.sa 16 == Short Description == 17 18 Accept popular payment methods in Saudi Arabia with PayLink Payment Gateway. 19 20 == Frequently Asked Questions == 21 22 = How do I set up the PayLink Payment Gateway? = 23 24 Please refer to the [installation guide](https://developer.paylink.sa/docs/woocommerce-plugin) for detailed instructions on setting up the PayLink Payment Gateway. 25 26 = What payment methods are supported? = 27 28 The plugin supports mada, Visa/Mastercard, American Express, Tabby, Tamara, STC Pay, URPay, and more. 29 30 == Changelog == 31 32 = 3.0.4 = 33 * Revised the readme file to comply with WordPress.org guidelines, including adding missing sections such as Short Description, Frequently Asked Questions, and adjusted contributor details and included links to documentation. 34 35 = 3.0.3 = 36 * Simplified Configuration: Removed `callback_url` and `card_brands` from `init_form_fields`, streamlining the setup process by reducing the number of required fields. 37 38 = 3.0.2 = 39 * Commented out `SupportedCardBrands`. 40 41 = 3.0.1 = 42 * Updated the Supported Card Brands Image. 43 * Updated the label of Live Credentials. 44 45 = 3.0.0 = 46 * No need to input linking keys in the testing environment. 47 * If linking keys are not entered in the live environment, the payment gateway is automatically disabled. 48 * Error and warning messages have been improved for clarity. 49 * Guidance messages have been added before redirection to the payment gateway. 50 * An error message has been added in case of any issues during the payment process. 51 * Simplified transition between the testing and live environments. 52 * Resolved conflict issue between activating the payment gateway and WooCommerce. 53 * Fixed the issue of the payment gateway not appearing on the checkout page. 54 * Our available payment methods are displayed on the checkout page in WordPress. 55 * Added a notification on the checkout page if the user is in the testing environment. 56 * Other features related to using WordPress and WooCommerce tools more effectively and up-to-date. 57 58 == Upgrade Notice == 59 60 = 3.0.3 = 61 This release simplifies the configuration process by removing unnecessary fields. It is recommended to update to this version for a smoother setup. 62 63 == Screenshots == 64 65 1. [Plugin settings page](https://www.youtube.com/watch?v=rbshNPwPD74) 66 2. [Checkout page with PayLink payment options](https://www.youtube.com/watch?v=Kg_U9V0QvhM)
Note: See TracChangeset
for help on using the changeset viewer.