diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 6e40a78..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/README.md b/README.md index ec620ea..906716d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ افزونه را فعال کنید -تنظیمات افزونه از طریق منوی تسویه حساب لرن پرس قابل دسترسی می باشد. +تنظیمات افزونه از طریق منوی « مبلغ پرداختی » لرن پرس قابل دسترسی می باشد. [https://www.zarinpal.com] diff --git a/assets/.DS_Store b/assets/.DS_Store deleted file mode 100644 index 52df12a..0000000 Binary files a/assets/.DS_Store and /dev/null differ diff --git a/assets/images/zarinpal.png b/assets/images/zarinpal.png index 4e25f33..1d9f568 100644 Binary files a/assets/images/zarinpal.png and b/assets/images/zarinpal.png differ diff --git a/inc/callback.php b/inc/callback.php new file mode 100644 index 0000000..6fe4c5c --- /dev/null +++ b/inc/callback.php @@ -0,0 +1,147 @@ +handle_callback(); + } + + /** + * @throws Exception + */ + public function handle_callback() + { + $request = $_REQUEST; + + if (isset($request['learn_press_zarinpal']) && intval($request['learn_press_zarinpal']) === 1) { + $order = LP_Order::instance($request['order_id']); + $setting = LP()->settings; + if (isset($request['Status']) && isset($request['Authority'])) { + $data = array( + "merchant_id" => $setting->get('zarinpal.merchant'), + "authority" => $_GET['Authority'], + "amount" => $order->get_total(), + ); + + $result = $this->rest_payment_verification($data); + if (empty($result['errors'])) { + if ($result['data']['code'] == 100) { + $request["RefID"] = $result['data']['ref_id']; + $this->authority = $_GET['Authority']; + $this->payment_status_completed($order, $request); + $this->redirect_to_return_url($order); + } elseif ($result['data']['code'] == 101) { + $this->redirect_to_return_url($order); + } + } else { + echo 'Error Code : ' . $result['errors']['code']; + $this->redirect_to_return_url($order); + } + } else { + $this->redirect_to_return_url($order); + } + + if ( ! isset($_SESSION)) { + session_start(); + } + $_SESSION['zarinpal_error'] = 1; + $this->redirect_to_checkout(); + } else { + $this->redirect_to_home(); + } + exit(); + } + + public function rest_payment_verification($data) + { + $jsonData = json_encode($data); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); + curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($jsonData), + )); + $result = curl_exec($ch); + $err = curl_error($ch); + $result = json_decode($result, true); + curl_close($ch); + if ($err) { + $result = (object)array("success" => 0); + } + + return $result; + } + + public function payment_status_completed($order, $request) + { + if ($order->has_status('completed')) { + exit; + } + + $this->payment_complete( + $order, + (! empty($request["RefID"]) ? $request["RefID"] : ''), + __('Payment has been successfully completed', 'learnpress-zarinpal') + ); + + update_post_meta($order->get_id(), '_zarinpal_RefID', $request['RefID']); + update_post_meta($order->get_id(), '_zarinpal_authority', $request['Authority']); + } + + public function payment_complete($order, $trans_id = '', $note = '') + { + $order->payment_complete($trans_id); + } + + public function redirect_to_return_url($order = null) + { + if ($order) { + $return_url = $order->get_checkout_order_received_url(); + } else { + $return_url = learn_press_get_endpoint_url('lp-order-received', '', learn_press_get_page_link('checkout')); + } + + wp_redirect(apply_filters('learn_press_get_return_url', $return_url, $order)); + exit(); + } + + public function redirect_to_checkout() + { + wp_redirect(esc_url(learn_press_get_page_link('checkout'))); + exit(); + } + + public function redirect_to_home() + { + wp_redirect(home_url()); + exit(); + } + + public function error_message() + { + if ( ! isset($_SESSION)) { + session_start(); + } + if (isset($_SESSION['zarinpal_error']) && intval($_SESSION['zarinpal_error']) === 1) { + $_SESSION['zarinpal_error'] = 0; + $template = learn_press_locate_template( + 'payment-error.php', + learn_press_template_path() . '/addons/zarinpal-payment/', + LP_ADDON_ZARINPAL_PAYMENT_TEMPLATE + ); + include $template; + } + } +} + +new Zarinpal_Callback_Handler(); diff --git a/inc/class-lp-gateway-zarinpal.php b/inc/class-lp-gateway-zarinpal.php index 8bca9d0..fe908d2 100644 --- a/inc/class-lp-gateway-zarinpal.php +++ b/inc/class-lp-gateway-zarinpal.php @@ -1,532 +1,390 @@ id = 'zarinpal'; - - $this->method_title = __( 'Zarinpal', 'learnpress-zarinpal' );; - $this->method_description = __( 'Make a payment with Zarinpal.', 'learnpress-zarinpal' ); - $this->icon = ''; - - // Get settings - $this->title = LP()->settings->get( "{$this->id}.title", $this->method_title ); - $this->description = LP()->settings->get( "{$this->id}.description", $this->method_description ); - - $settings = LP()->settings; - - // Add default values for fresh installs - if ( $settings->get( "{$this->id}.enable" ) ) { - $this->settings = array(); - $this->settings['merchant'] = $settings->get( "{$this->id}.merchant" ); - } - - $this->merchant = $this->settings['merchant']; - - if ( did_action( 'learn_press/zarinpal-add-on/loaded' ) ) { - return; - } - - // check payment gateway enable - add_filter( 'learn-press/payment-gateway/' . $this->id . '/available', array( - $this, - 'zarinpal_available' - ), 10, 2 ); - - do_action( 'learn_press/zarinpal-add-on/loaded' ); - - parent::__construct(); - - // web hook - if ( did_action( 'init' ) ) { - $this->register_web_hook(); - } else { - add_action( 'init', array( $this, 'register_web_hook' ) ); - } - add_action( 'learn_press_web_hooks_processed', array( $this, 'web_hook_process_zarinpal' ) ); - - add_action("learn-press/before-checkout-order-review", array( $this, 'error_message' )); - } - - /** - * Register web hook. - * - * @return array - */ - public function register_web_hook() { - learn_press_register_web_hook( 'zarinpal', 'learn_press_zarinpal' ); - } - - /** - * Admin payment settings. - * - * @return array - */ - public function get_settings() { - - return apply_filters( 'learn-press/gateway-payment/zarinpal/settings', - array( - array( - 'title' => __( 'Enable', 'learnpress-zarinpal' ), - 'id' => '[enable]', - 'default' => 'no', - 'type' => 'yes-no' - ), - array( - 'type' => 'text', - 'title' => __( 'Title', 'learnpress-zarinpal' ), - 'default' => __( 'Zarinpal', 'learnpress-zarinpal' ), - 'id' => '[title]', - 'class' => 'regular-text', - 'visibility' => array( - 'state' => 'show', - 'conditional' => array( - array( - 'field' => '[enable]', - 'compare' => '=', - 'value' => 'yes' - ) - ) - ) - ), - array( - 'type' => 'textarea', - 'title' => __( 'Description', 'learnpress-zarinpal' ), - 'default' => __( 'Pay with Zarinpal', 'learnpress-zarinpal' ), - 'id' => '[description]', - 'editor' => array( - 'textarea_rows' => 5 - ), - 'css' => 'height: 100px;', - 'visibility' => array( - 'state' => 'show', - 'conditional' => array( - array( - 'field' => '[enable]', - 'compare' => '=', - 'value' => 'yes' - ) - ) - ) - ), - array( - 'title' => __( 'Merchant ID', 'learnpress-zarinpal' ), - 'id' => '[merchant]', - 'type' => 'text', - 'visibility' => array( - 'state' => 'show', - 'conditional' => array( - array( - 'field' => '[enable]', - 'compare' => '=', - 'value' => 'yes' - ) - ) - ) - ) - ) - ); - } - - /** - * Payment form. - */ - public function get_payment_form() { - ob_start(); - $template = learn_press_locate_template( 'form.php', learn_press_template_path() . '/addons/zarinpal-payment/', LP_ADDON_ZARINPAL_PAYMENT_TEMPLATE ); - include $template; - - return ob_get_clean(); - } - - /** - * Error message. - * - * @return array - */ - public function error_message() { - if(!isset($_SESSION)) - session_start(); - if(isset($_SESSION['zarinpal_error']) && intval($_SESSION['zarinpal_error']) === 1) { - $_SESSION['zarinpal_error'] = 0; - $template = learn_press_locate_template( 'payment-error.php', learn_press_template_path() . '/addons/zarinpal-payment/', LP_ADDON_ZARINPAL_PAYMENT_TEMPLATE ); - include $template; - } - } - - /** - * @return mixed - */ - public function get_icon() { - if ( empty( $this->icon ) ) { - $this->icon = LP_ADDON_ZARINPAL_PAYMENT_URL . 'assets/images/zarinpal.png'; - } - - return parent::get_icon(); - } - - /** - * Check gateway available. - * - * @return bool - */ - public function zarinpal_available() { - - if ( LP()->settings->get( "{$this->id}.enable" ) != 'yes' ) { - return false; - } - - return true; - } - - /** - * Get form data. - * - * @return array - */ - public function get_form_data() { - if ( $this->order ) { - $user = learn_press_get_current_user(); - $currency_code = learn_press_get_currency() ; - if ($currency_code == 'IRR') { - $amount = $this->order->order_total; - } else { - $amount = $this->order->order_total * 10; - } - - $this->form_data = array( - 'amount' => $amount, - 'currency' => strtolower( learn_press_get_currency() ), - 'token' => $this->token, - 'description' => sprintf( __("Charge for %s","learnpress-zarinpal"), $user->get_data( 'email' ) ), - 'customer' => array( - 'name' => $user->get_data( 'display_name' ), - 'billing_email' => $user->get_data( 'email' ), - ), - 'errors' => isset( $this->posted['form_errors'] ) ? $this->posted['form_errors'] : '' - ); - } - - return $this->form_data; - } - - /** - * Validate form fields. - * - * @return bool - * @throws Exception - * @throws string - */ - public function validate_fields() { - $posted = learn_press_get_request( 'learn-press-zarinpal' ); - $email = !empty( $posted['email'] ) ? $posted['email'] : ""; - $mobile = !empty( $posted['mobile'] ) ? $posted['mobile'] : ""; - $error_message = array(); - if ( !empty( $email ) && !filter_var($email, FILTER_VALIDATE_EMAIL)) { - $error_message[] = __( 'Invalid email format.', 'learnpress-zarinpal' ); - } - if ( !empty( $mobile ) && !preg_match("/^(09)(\d{9})$/", $mobile)) { - $error_message[] = __( 'Invalid mobile format.', 'learnpress-zarinpal' ); - } - - if ( $error = sizeof( $error_message ) ) { - throw new Exception( sprintf( '
%s
', join( '
', $error_message ) ), 8000 ); - } - $this->posted = $posted; - - return $error ? false : true; - } - - /** - * Zarinpal payment process. - * - * @param $order - * - * @return array - * @throws string - */ - public function process_payment( $order ) { - $this->order = learn_press_get_order( $order ); - $zarinpal = $this->get_zarinpal_authority(); - $gateway_url = $this->startPay.$this->authority; - $json = array( - 'result' => $zarinpal ? 'success' : 'fail', - 'redirect' => $zarinpal ? $gateway_url : '' - ); - - return $json; - } - - - /** - * Get Zarinpal authority. - * - * @return bool|object - * @throws string - */ - public function get_zarinpal_authority() { - if ( $this->get_form_data() ) { - $checkout = LP()->checkout(); - - - $data = array("merchant_id" => $this->merchant, - "amount" => $this->form_data['amount'], - "callback_url" => get_site_url() . '/?' . learn_press_get_web_hook( 'zarinpal' ) . '=1&order_id='.$this->order->get_id(), - "description" => $this->form_data['description'], - "metadata" => [ "email" => (!empty($this->posted['email'])) ? $this->posted['email'] : "0" - ,"mobile"=> (!empty($this->posted['mobile'])) ? $this->posted['mobile'] : "0"], +defined('ABSPATH') || exit; + +if ( ! class_exists('LP_Gateway_Zarinpal')) { + /** + * Class LP_Gateway_Zarinpal + */ + class LP_Gateway_Zarinpal extends LP_Gateway_Abstract + { + + /** + * @var array + */ + private $form_data = array(); + + /** + * @var string + */ + private $startPay = 'https://www.zarinpal.com/pg/StartPay/'; + + + /** + * @var string + */ + private $restPaymentRequestUrl = 'https://api.zarinpal.com/pg/v4/payment/request.json'; + + /** + * @var string + */ + private $restPaymentVerification = 'https://api.zarinpal.com/pg/v4/payment/verify.json'; + + /** + * @var string + */ + private $soap = false; + + /** + * @var string + */ + private $merchant = null; + + /** + * @var array|null + */ + protected $settings = null; + + /** + * @var null + */ + protected $order = null; + + /** + * @var null + */ + protected $posted = null; + + /** + * + * @var string + */ + protected $authority = null; + + /** + * LP_Gateway_Zarinpal constructor. + */ + public function __construct() + { + $this->id = 'zarinpal'; + + $this->method_title = __('Zarinpal', 'learnpress-zarinpal');; + $this->method_description = __('Make a payment with Zarinpal.', 'learnpress-zarinpal'); + $this->icon = LP_ADDON_ZARINPAL_PAYMENT_URL . '/assets/images/zarinpal.png'; + + // Get settings + $this->title = LP()->settings->get("{$this->id}.title", $this->method_title); + $this->description = LP()->settings->get("{$this->id}.description", $this->method_description); + + $settings = LP()->settings; + + // Add default values for fresh installs + if ($settings->get("{$this->id}.enable")) { + $this->settings = array(); + $this->settings['merchant'] = $settings->get("{$this->id}.merchant"); + } + + $this->merchant = $this->settings['merchant']; + + if (did_action('learn_press/zarinpal-add-on/loaded')) { + return; + } + + // check payment gateway enable + add_filter('learn-press/payment-gateway/' . $this->id . '/available', array( + $this, + 'zarinpal_available', + ), 10, 2); + + do_action('learn_press/zarinpal-add-on/loaded'); + + parent::__construct(); + + add_action("learn-press/before-checkout-order-review", array($this, 'error_message')); + } + + /** + * Admin payment settings. + * + * @return array + */ + public function get_settings() + { + return apply_filters( + 'learn-press/gateway-payment/zarinpal/settings', + array( + array( + 'type' => 'title', + ), + array( + 'title' => __('Enable', 'learnpress-zarinpal'), + 'id' => '[enable]', + 'default' => 'no', + 'type' => 'checkbox', + ), + array( + 'type' => 'text', + 'title' => __('Title', 'learnpress-zarinpal'), + 'default' => __('Zarinpal', 'learnpress-zarinpal'), + 'id' => '[title]', + 'class' => 'regular-text', + 'visibility' => array( + 'state' => 'show', + 'conditional' => array( + array( + 'field' => '[enable]', + 'compare' => '=', + 'value' => 'yes', + ), + ), + ), + ), + array( + 'type' => 'textarea', + 'title' => __('Description', 'learnpress-zarinpal'), + 'default' => __('Pay with Zarinpal', 'learnpress-zarinpal'), + 'id' => '[description]', + 'editor' => array( + 'textarea_rows' => 5, + ), + 'css' => 'height: 100px;', + 'visibility' => array( + 'state' => 'show', + 'conditional' => array( + array( + 'field' => '[enable]', + 'compare' => '=', + 'value' => 'yes', + ), + ), + ), + ), + array( + 'title' => __('Merchant ID', 'learnpress-zarinpal'), + 'id' => '[merchant]', + 'type' => 'text', + 'visibility' => array( + 'state' => 'show', + 'conditional' => array( + array( + 'field' => '[enable]', + 'compare' => '=', + 'value' => 'yes', + ), + ), + ), + ), + array( + 'type' => 'sectionend', + ), + ) + ); + } + + /** + * Payment form. + */ + public function get_payment_form() + { + ob_start(); + $template = learn_press_locate_template( + 'form.php', + learn_press_template_path() . '/addons/zarinpal-payment/', + LP_ADDON_ZARINPAL_PAYMENT_TEMPLATE + ); + include $template; + + return ob_get_clean(); + } + + /** + * Error message. + * + * @return array + */ + public function error_message() + { + if ( ! isset($_SESSION)) { + session_start(); + } + if (isset($_SESSION['zarinpal_error']) && intval($_SESSION['zarinpal_error']) === 1) { + $_SESSION['zarinpal_error'] = 0; + $template = learn_press_locate_template( + 'payment-error.php', + learn_press_template_path() . '/addons/zarinpal-payment/', + LP_ADDON_ZARINPAL_PAYMENT_TEMPLATE + ); + include $template; + } + } + + + /** + * Check gateway available. + * + * @return bool + */ + public function zarinpal_available() + { + if (LP()->settings->get("{$this->id}.enable") != 'yes') { + return false; + } + + return true; + } + + /** + * Get form data. + * + * @return array + */ + public function get_form_data() + { + if ($this->order) { + $user = learn_press_get_current_user(); + + $this->form_data = array( + 'amount' => $this->order->get_total(), + 'description' => sprintf( + "خرید کاربر %s %s شماره سفارش : %s", + $user->get_first_name(), + $user->get_last_name(), + $this->order->get_id() + ), + 'customer' => array( + 'name' => $user->get_first_name() . " " . $user->get_last_name(), + 'billing_email' => $user->get_data('email'), + ), + 'errors' => isset($this->posted['form_errors']) ? $this->posted['form_errors'] : '', + ); + } + + return $this->form_data; + } + + /** + * Validate form fields. + * + * @return bool + * @throws Exception + * @throws string + */ + public function validate_fields() + { + $posted = learn_press_get_request('learn-press-zarinpal'); + $email = ! empty($posted['email']) ? $posted['email'] : ""; + $mobile = ! empty($posted['mobile']) ? $posted['mobile'] : ""; + $error_message = array(); + if ( ! empty($email) && ! filter_var($email, FILTER_VALIDATE_EMAIL)) { + $error_message[] = __('Invalid email format.', 'learnpress-zarinpal'); + } + if ( ! empty($mobile) && ! preg_match("/^(09)(\d{9})$/", $mobile)) { + $error_message[] = __('Invalid mobile format.', 'learnpress-zarinpal'); + } + + if ($error = sizeof($error_message)) { + throw new Exception(sprintf('
%s
', join('
', $error_message)), 8000); + } + $this->posted = $posted; + + return $error ? false : true; + } + + /** + * Zarinpal payment process. + * + * @param $order + * + * @return array + * @throws string + */ + public function process_payment($order) + { + $this->order = learn_press_get_order($order); + $authority = $this->get_zarinpal_authority(); + $gateway_url = $this->startPay . $this->authority; + + return array( + 'result' => $authority ? 'success' : 'fail', + 'redirect' => $authority ? $gateway_url : '', + ); + } + + + /** + * Get Zarinpal authority. + * + * @return bool|object + * @throws string + */ + public function get_zarinpal_authority() + { + if ($this->get_form_data()) { + $data = array( + "merchant_id" => $this->merchant, + "amount" => $this->form_data['amount'], + "currency" => learn_press_get_currency(), + "callback_url" => LP_ADDON_ZARINPAL_PAYMENT_URL . "inc/callback.php" . '/?' . 'learn_press_zarinpal=1&order_id=' . $this->order->get_id( + ), + "description" => $this->form_data['description'], + "metadata" => [ + 'order_id' => strval($this->order->get_id()), + ], ); - + if ( ! empty($this->posted['email'])) { + $data['metadata']['email'] = $this->posted['email']; + } + if ( ! empty($this->posted['mobile'])) { + $data['metadata']['mobile'] = $this->posted['mobile']; + } $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) + 'Content-Length: ' . strlen($jsonData), )); $result = curl_exec($ch); - $err = curl_error($ch); + $err = curl_error($ch); $result = json_decode($result, true, JSON_PRETTY_PRINT); curl_close($ch); - - if ($err) { echo "cURL Error #:" . $err; } else { if (empty($result['errors'])) { if ($result['data']['code'] == 100) { - $this->authority = $result['data']["authority"]; + return true; - // header('Location: https://www.zarinpal.com/pg/StartPay/' . $result['data']["authority"]); + // header('Location: https://www.zarinpal.com/pg/StartPay/' . $result['data']["authority"]); } } else { - echo'Error Code: ' . $result['errors']['code']; - echo'message: ' . $result['errors']['message']; - + $error_message = array(); + $error_message[] = $result['errors']['code']; + throw new Exception( + sprintf('
کد خطا : %s
', join('
', $error_message)), 8000 + ); } } - } - return false; - } - - /** - * Handle a web hook - * - */ - public function web_hook_process_zarinpal() { - $request = $_REQUEST; - if(isset($request['learn_press_zarinpal']) && intval($request['learn_press_zarinpal']) === 1) { - if ($request['Status'] == 'OK') { - $order = LP_Order::instance( $request['order_id'] ); - $currency_code = learn_press_get_currency(); - if ($currency_code == 'IRR') { - $amount = $order->order_total; - } else { - $amount = $order->order_total * 10; - } - - - - $Authority = $_GET['Authority']; - $data = array("merchant_id" => $this->merchant, "authority" => $Authority, "amount" => $amount,); - $result = $this->rest_payment_verification($data); - - - - - - if ($result['data']['code'] == 100) { - //echo 'Transation success. RefID:' . $result['data']['ref_id']; - $request["RefID"] = $result['data']['ref_id']; - $this->authority = intval($_GET['Authority']); - $this->payment_status_completed($order , $request); - wp_redirect(esc_url( $this->get_return_url( $order ) )); - exit(); - } else { - echo'code: ' . $result['errors']['code']; - echo'message: ' . $result['errors']['message']; - } - + } - } - - if(!isset($_SESSION)) - session_start(); - $_SESSION['zarinpal_error'] = 1; - - wp_redirect(esc_url( learn_press_get_page_link( 'checkout' ) )); - exit(); - } - } - - /** - * Zarinpal REST payment request - * - */ - public function rest_payment_request($data) { - $jsonData = json_encode($data); - $ch = curl_init($this->restPaymentRequestUrl); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - $result = curl_exec($ch); - $err = curl_error($ch); - $result = json_decode($result); - curl_close($ch); - if ($err) { - $result = (object) array("success"=>0); - } - return $result; - } - - /** - * Zarinpal REST payment verification - * - */ - public function rest_payment_verification($data) { - $jsonData = json_encode($data); - $ch = curl_init($this->restPaymentVerification); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - $result = curl_exec($ch); - $err = curl_error($ch); - $result = json_decode($result); - curl_close($ch); - if ($err) { - $result = (object) array("success"=>0); - } - return $result; - } - - /** - * Handle a completed payment - * - * @param LP_Order - * @param request - */ - protected function payment_status_completed( $order, $request ) { - - // order status is already completed - if ( $order->has_status( 'completed' ) ) { - exit; - } - - $this->payment_complete( $order, ( !empty( $request["RefID"] ) ? $request["RefID"] : '' ), __( 'Payment has been successfully completed', 'learnpress-zarinpal' ) ); - - update_post_meta( $order->get_id(), '_zarinpal_RefID', $request['RefID'] ); - update_post_meta( $order->get_id(), '_zarinpal_authority', $request['Authority'] ); - } - - /** - * Handle a pending payment - * - * @param LP_Order - * @param request - */ - protected function payment_status_pending( $order, $request ) { - $this->payment_status_completed( $order, $request ); - } - - /** - * @param LP_Order - * @param string $txn_id - * @param string $note - not use - */ - public function payment_complete( $order, $trans_id = '', $note = '' ) { - $order->payment_complete( $trans_id ); - } - } + return false; + } + } } \ No newline at end of file diff --git a/inc/load.php b/inc/load.php index 5db0a08..486deb5 100644 --- a/inc/load.php +++ b/inc/load.php @@ -1,21 +1,23 @@ settings->get( 'learn_press_zarinpal.enable' ) == 'yes' ) { + + if (LP()->settings->get('learn_press_zarinpal.enable') == 'yes') { $user = learn_press_get_current_user(); - learn_press_assets()->enqueue_script( 'learn-press-zarinpal-payment', $this->get_plugin_url( 'assets/js/script.js' ), array() ); - learn_press_assets()->enqueue_style( 'learn-press-zarinpal', $this->get_plugin_url( 'assets/css/style.css' ), array() ); + learn_press_assets()->enqueue_script('learn-press-zarinpal-payment', $this->get_plugin_url('assets/js/script.js'), array()); + learn_press_assets()->enqueue_style('learn-press-zarinpal', $this->get_plugin_url('assets/css/style.css'), array()); $data = array( - 'plugin_url' => plugins_url( '', LP_ADDON_ZARINPAL_PAYMENT_FILE ) + 'plugin_url' => plugins_url('', LP_ADDON_ZARINPAL_PAYMENT_FILE) ); - wp_localize_script( 'learn-press-zarinpal', 'learn_press_zarinpal_info', $data ); + wp_localize_script('learn-press-zarinpal', 'learn_press_zarinpal_info', $data); } } @@ -89,7 +96,8 @@ protected function _enqueue_assets() { * * @return mixed */ - public function add_payment( $methods ) { + public function add_payment($methods) + { $methods['zarinpal'] = 'LP_Gateway_Zarinpal'; return $methods; @@ -100,10 +108,11 @@ public function add_payment( $methods ) { * * @return array */ - public function plugin_links() { - $links[] = '' . __( 'Settings', 'learnpress-zarinpal' ) . ''; + public function plugin_links() + { + $links[] = '' . __('Settings', 'learnpress-zarinpal') . ''; return $links; } } -} \ No newline at end of file +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..ed9f817 --- /dev/null +++ b/index.php @@ -0,0 +1,75 @@ + +
+

%s addon version %s requires %s version %s or higher is installed and activated.', 'learnpress-zarinpal'), + __('LearnPress Zarinpal Payment', 'learnpress-zarinpal'), + LP_ADDON_ZARINPAL_PAYMENT_VER, + sprintf('%s', admin_url('plugin-install.php?tab=search&type=term&s=learnpress'), __('LearnPress', 'learnpress-zarinpal')), + LP_ADDON_ZARINPAL_PAYMENT_REQUIRE_VER + ), + array( + 'a' => array( + 'href' => array(), + 'blank' => array() + ), + 'strong' => array() + ) + ); ?> +

+
+ -
-

%s addon version %s requires %s version %s or higher is installed and activated.', 'learnpress-zarinpal' ), - __( 'LearnPress Zarinpal Payment', 'learnpress-zarinpal' ), - LP_ADDON_ZARINPAL_PAYMENT_VER, - sprintf( '%s', admin_url( 'plugin-install.php?tab=search&type=term&s=learnpress' ), __( 'LearnPress', 'learnpress-zarinpal' ) ), - LP_ADDON_ZARINPAL_PAYMENT_REQUIRE_VER - ), - array( - 'a' => array( - 'href' => array(), - 'blank' => array() - ), - 'strong' => array() - ) - ); ?> -

-
- -settings; ?> +settings; ?> -

get_description(); ?>

+

get_description(); ?>

-
+

- - -

+ + +

-
+

- + -

+ placeholder="09123456789 حتما با 09 شروع شود"/> +

-
+
+ diff --git a/templates/payment-error.php b/templates/payment-error.php index 54030da..720fe0e 100644 --- a/templates/payment-error.php +++ b/templates/payment-error.php @@ -1,23 +1,24 @@ settings; ?>
-
-
+
+
\ No newline at end of file