From 10f8b82716e1a1e3bc8643cfaa5b0f85d50a76ad Mon Sep 17 00:00:00 2001 From: chapdel Date: Mon, 12 Feb 2024 19:33:07 +0100 Subject: [PATCH] Quick update --- .vscode/settings.json | 3 - admin/class-notchpay-give-admin.php | 33 ++++++++-- includes/class-notchpay-give-loader.php | 2 +- includes/class-notchpay-give.php | 85 +++++++++---------------- languages/notchpay-give.pot | 0 notchpay-give.php | 7 +- public/class-notchpay-give-public.php | 2 +- readme.txt | 19 ++---- 8 files changed, 68 insertions(+), 83 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 languages/notchpay-give.pot diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 13ee2b0..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nuxt.isNuxtApp": false -} \ No newline at end of file diff --git a/admin/class-notchpay-give-admin.php b/admin/class-notchpay-give-admin.php index 0a63a40..d39e594 100644 --- a/admin/class-notchpay-give-admin.php +++ b/admin/class-notchpay-give-admin.php @@ -5,7 +5,7 @@ * * @package Give * @subpackage Gateways - * @author Chapdel KAMGA + * @author Stephen Amaza * @license https://opensource.org/licenses/gpl-license GNU Public License * @link https://notchpay.co * @since 1.0.0 @@ -19,7 +19,7 @@ * * @package NotchPay_Give * @subpackage Gateways - * @author Chapdel + * @author Stephen */ class NotchPay_Give_Admin { @@ -193,25 +193,44 @@ public function register_settings( $settings ) { 'id' => 'give_title_notchpay', ], [ - 'name' => esc_html__( 'Sandbox Public Key', 'notchpay-give' ), + 'name' => esc_html__( 'Test Public Key', 'notchpay-give' ), 'desc' => esc_html__( 'Enter your Notch Pay Test Public Key', 'notchpay-give' ), 'id' => 'notchpay_test_public_key', - 'type' => 'password', + 'type' => 'text', 'row_classes' => 'give-notchpay-test-public-key', ], + [ + 'name' => esc_html__( 'Test Secret Key', 'notchpay-give' ), + 'desc' => esc_html__( 'Enter your Notch Pay Test Secret Key', 'notchpay-give' ), + 'id' => 'notchpay_test_secret_key', + 'type' => 'text', + 'row_classes' => 'give-notchpay-test-secret-key', + ], [ 'name' => esc_html__( 'Live Public Key', 'notchpay-give' ), 'desc' => esc_html__( 'Enter your Notch Pay Live Public Key', 'notchpay-give' ), 'id' => 'notchpay_live_public_key', - 'type' => 'password', + 'type' => 'text', 'row_classes' => 'give-notchpay-live-public-key', ], + [ + 'name' => esc_html__( 'Live Secret Key', 'notchpay-give' ), + 'desc' => esc_html__( 'Enter your Notch Pay Live Secret Key', 'notchpay-give' ), + 'id' => 'notchpay_live_secret_key', + 'type' => 'text', + 'row_classes' => 'give-notchpay-live-secret-key', + ], + [ 'name' => esc_html__( 'Billing Details', 'notchpay-give' ), - 'desc' => esc_html__( 'This is not required by Notch Pay (except email)', 'notchpay-give' ), + 'desc' => esc_html__( 'This will enable you to collect donor details. This is not required by Notch Pay (except email) but you might need to collect all information for record purposes', 'notchpay-give' ), 'id' => 'notchpay_billing_details', - 'type' => 'hidden', + 'type' => 'radio_inline', 'default' => 'disabled', + 'options' => [ + 'enabled' => esc_html__( 'Enabled', 'notchpay-give' ), + 'disabled' => esc_html__( 'Disabled', 'notchpay-give' ), + ], ], [ 'type' => 'sectionend', diff --git a/includes/class-notchpay-give-loader.php b/includes/class-notchpay-give-loader.php index 1172fb4..71237d1 100644 --- a/includes/class-notchpay-give-loader.php +++ b/includes/class-notchpay-give-loader.php @@ -19,7 +19,7 @@ * * @package NotchPay_Give * @subpackage NotchPay_Give/includes - * @author Notch Pay + * @author Notch Pay */ class NotchPay_Give_Loader { diff --git a/includes/class-notchpay-give.php b/includes/class-notchpay-give.php index 1dda240..2ec2712 100644 --- a/includes/class-notchpay-give.php +++ b/includes/class-notchpay-give.php @@ -8,12 +8,14 @@ * * @package Give * @subpackage Gateways - * @author Chapdel KAMGA + * @author Chapdel KAMGA * @license https://opensource.org/licenses/gpl-license GNU Public License * @link https://notchpay.co * @since 1.0.0 */ +use Give\Framework\PaymentGateways\Commands\RespondToBrowser; + /** * The core plugin class. * @@ -26,7 +28,7 @@ * @since 1.0.0 * @package NotchPay_Give * @subpackage NotchPay_Give/includes - * @author Notch Pay + * @author Notch Pay */ class give_notchpay_plugin_tracker @@ -113,8 +115,8 @@ class NotchPay_Give */ public function __construct() { - if (defined('PLUGIN_NAME_VERSION')) { - $this->version = PLUGIN_NAME_VERSION; + if (defined('NP_GIVE_PLUGIN_NAME_VERSION')) { + $this->version = NP_GIVE_PLUGIN_NAME_VERSION; } else { $this->version = '1.0.0'; } @@ -299,16 +301,11 @@ function give_notchpay_credit_card_form($form_id, $echo = true) function give_process_notchpay_purchase($purchase_data) { - - - - // Make sure we don't have any left over errors present. give_clear_errors(); // Any errors? $errors = give_get_errors(); - if (!$errors) { $form_id = intval($purchase_data['post_data']['give-form-id']); @@ -332,12 +329,10 @@ function give_process_notchpay_purchase($purchase_data) // Record the pending payment $payment = give_insert_payment($payment_data); - - if (!$payment) { // Record the error - give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending donor to Notch Pay. Payment data: %s', 'give'), json_encode($payment_data)), $payment); + give_record_log(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending donor to Notch Pay. Payment data: %s', 'give'), json_encode($payment_data)), $payment); // Problems? send back give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway'] . "&message=-some weird error happened-&payment_id=" . json_encode($payment)); } else { @@ -350,14 +345,13 @@ function give_process_notchpay_purchase($purchase_data) $public_key = give_get_option('notchpay_live_public_key'); } - - $ref = $purchase_data['purchase_key']; // . '-' . time() . '-' . preg_replace("/[^0-9a-z_]/i", "_", $purchase_data['user_email']); $currency = give_get_currency(); $verify_url = home_url() . '?' . http_build_query( [ - NotchPay_Give::API_QUERY_VAR => 'verify' + NotchPay_Give::API_QUERY_VAR => 'verify', + 'reference' => $ref, ] ); @@ -365,25 +359,11 @@ function give_process_notchpay_purchase($purchase_data) $url = "https://api.notchpay.co/payments/initialize"; $fields = [ 'email' => $payment_data['user_email'], + 'name' => isset($payment_data['user_info'])? (isset($payment_data['user_info']['first_name']) ? $payment_data['user_info']['first_name'] : null ) : null, 'amount' => $payment_data['price'], 'reference' => $ref, 'callback' => $verify_url, - 'type' => "heart-donation", 'currency' => $currency, - 'metadata' => [ - 'custom_fields' => [ - [ - 'display_name' => 'Form Title', - 'variable_name' => 'form_title', - 'value' => $payment_data['give_form_title'] - ], - [ - 'display_name' => 'Plugin', - 'variable_name' => 'plugin', - 'value' => 'give' - ] - ] - ] ]; $fields_string = http_build_query($fields); @@ -405,10 +385,16 @@ function give_process_notchpay_purchase($purchase_data) //execute post $result = curl_exec($ch); $json_response = json_decode($result, true); - if (isset($json_response['status']) && $json_response['code'] == 201) { + give_insert_payment_note($payment, 'ERROR: fdfddffddf'); + + + if ($json_response['status'] && $json_response['code'] == 201) { wp_redirect($json_response['authorization_url']); exit; - } else { + } else if($json_response['status'] && $json_response['code'] == 422) { + // todo: show error message + give_send_back_to_checkout('?payment-mode=notchpay' . '&error=' . $json_response['message']); + }else { give_send_back_to_checkout('?payment-mode=notchpay' . '&error=' . $json_response['message']); } //-------------- @@ -420,7 +406,6 @@ function give_process_notchpay_purchase($purchase_data) } } - add_action('give_gateway_notchpay', 'give_process_notchpay_purchase'); } @@ -475,15 +460,17 @@ public function Verify_transaction() die('not a valid response'); } + + $give_ref = $_GET['notchpay_trxref']; $ref = $_GET['reference']; $status = $_GET['status']; $payment = give_get_payment_by('key', $give_ref); + // die(json_encode($payment)); if ($payment === false) { die('not a valid ref'); } - if (give_is_test_mode()) { $public_key = give_get_option('notchpay_test_public_key'); } else { @@ -500,18 +487,12 @@ public function Verify_transaction() $request = wp_remote_get($url, $args); - - if (is_wp_error($request)) { - return false; // Bail early } - - $body = wp_remote_retrieve_body($request); - $result = json_decode($body); // var_dump($result); @@ -529,12 +510,16 @@ public function Verify_transaction() $pstk_logger->log_transaction_success($ref); // + // the transaction was successful, you can deliver value give_update_payment_status($payment->ID, 'complete'); - - - + // echo json_encode( + // [ + // 'url' => give_get_success_page_uri(), + // 'status' => 'given', + // ] + // ); wp_redirect(give_get_success_page_uri()); exit; } else { @@ -550,21 +535,13 @@ public function Verify_transaction() $error_message = "Payment failed on Notch Pay"; break; } - - // fix data - + // the transaction was not successful, do not deliver value' give_update_payment_status($payment->ID, 'failed'); + give_insert_payment_note($payment, 'ERROR: ' . $error_message); + wp_redirect(give_get_failed_transaction_uri()); exit; - /* give_insert_payment_note($payment, 'ERROR: ' . $error_message); - echo json_encode( - [ - 'status' => 'not-given', - 'comment_content' => $error_message, - 'message' => "Transaction was not successful: Last gateway response was: " . $error_message, - ] - ); */ } } } diff --git a/languages/notchpay-give.pot b/languages/notchpay-give.pot new file mode 100644 index 0000000..e69de29 diff --git a/notchpay-give.php b/notchpay-give.php index 8cb64f1..cf2a192 100644 --- a/notchpay-give.php +++ b/notchpay-give.php @@ -16,7 +16,7 @@ * Plugin Name: Notch Pay for Give * Plugin URI: http://wordpress.org/plugins/notchpay-give * Description: Notch Pay integration for accepting donation with local payments and mobile money - * Version: 1.0.0 + * Version: 1.0.1 * Author: Notch Pay * Author URI: https://notchpay.co * License: GPL-2.0+ @@ -35,10 +35,7 @@ * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ -if (!defined('PLUGIN_NAME_VERSION')) { - define('PLUGIN_NAME_VERSION', '1.0.0'); -} - +define('NP_GIVE_PLUGIN_NAME_VERSION', '2.0.0'); /** * The code that runs during plugin activation. diff --git a/public/class-notchpay-give-public.php b/public/class-notchpay-give-public.php index 933c9cf..b27ba9c 100644 --- a/public/class-notchpay-give-public.php +++ b/public/class-notchpay-give-public.php @@ -18,7 +18,7 @@ * * @package NotchPay_Give * @subpackage NotchPay_Give/public - * @author Notch Pay + * @author Notch Pay */ class NotchPay_Give_Public { diff --git a/readme.txt b/readme.txt index 8ffd43b..6b3d2e8 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ -=== Notch Pay for Give === +=== Notch Pay Payment for Give === Contributors: notchpay, chapdel Donate link: https://notchpay.co/donate Tags: give, notchpay, payment, donation,mobilemoney,orangemoney Requires at least: 3.0.1 -Tested up to: 5.9 -Stable tag: 1.0.0 +Tested up to: 6.4 +Stable tag: 1.0.1 Requires PHP: 5.6 and higher License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -58,7 +58,7 @@ The manual installation method involves downloading our payment plugin and uploa = Where can I find help and documentation to understand Notch Pay? = -You can find help and information on Notch Pay on our [Help Desk](https://notchpay.co/help) +You can find help and information on Notch Pay on our [Help Desk](https://support.notchpay.co) = Where can I get support or talk to other users? = @@ -68,12 +68,7 @@ If you get stuck, you can ask for help in the [Notch Pay for Give Plugin Forum]( Yes you can! Join in on our [GitHub repository](https://github.com/notchpay/notchpay-give) :) - -== Changelog == - += 1.0.1 = +* Compatibility with WordPress 6.4 and PHP 8 = 1.0.0 = -* First release - -== Screenshots == - -1. The slick Notch Pay settings panel. +* First release \ No newline at end of file