Skip to content

Commit

Permalink
Quick update
Browse files Browse the repository at this point in the history
  • Loading branch information
chapdel committed Feb 12, 2024
1 parent 2c66b6b commit 10f8b82
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 83 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

33 changes: 26 additions & 7 deletions admin/class-notchpay-give-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package Give
* @subpackage Gateways
* @author Chapdel KAMGA<chapdel@notchpay.co>
* @author Stephen Amaza <steve@notchpay.com>
* @license https://opensource.org/licenses/gpl-license GNU Public License
* @link https://notchpay.co
* @since 1.0.0
Expand All @@ -19,7 +19,7 @@
*
* @package NotchPay_Give
* @subpackage Gateways
* @author Chapdel <chapdel@notchpay.co>
* @author Stephen <steve@notchpay.com>
*/
class NotchPay_Give_Admin
{
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion includes/class-notchpay-give-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @package NotchPay_Give
* @subpackage NotchPay_Give/includes
* @author Notch Pay <hello@notchpay.com>
* @author Notch Pay <hello@notchpay.co>
*/
class NotchPay_Give_Loader
{
Expand Down
85 changes: 31 additions & 54 deletions includes/class-notchpay-give.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
*
* @package Give
* @subpackage Gateways
* @author Chapdel KAMGA<[email protected]>
* @author Chapdel KAMGA <[email protected]>
* @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.
*
Expand All @@ -26,7 +28,7 @@
* @since 1.0.0
* @package NotchPay_Give
* @subpackage NotchPay_Give/includes
* @author Notch Pay <hello@notchpay.com>
* @author Notch Pay <hello@notchpay.co>
*/

class give_notchpay_plugin_tracker
Expand Down Expand Up @@ -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';
}
Expand Down Expand Up @@ -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']);
Expand All @@ -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 {
Expand All @@ -350,40 +345,25 @@ 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,
]
);

//----------
$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);
Expand All @@ -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']);
}
//--------------
Expand All @@ -420,7 +406,6 @@ function give_process_notchpay_purchase($purchase_data)
}
}


add_action('give_gateway_notchpay', 'give_process_notchpay_purchase');
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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,
]
); */
}
}
}
Empty file added languages/notchpay-give.pot
Empty file.
7 changes: 2 additions & 5 deletions notchpay-give.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion public/class-notchpay-give-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @package NotchPay_Give
* @subpackage NotchPay_Give/public
* @author Notch Pay <hello@notchpay.com>
* @author Notch Pay <hello@notchpay.co>
*/
class NotchPay_Give_Public
{
Expand Down
19 changes: 7 additions & 12 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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? =

Expand All @@ -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

0 comments on commit 10f8b82

Please sign in to comment.