Skip to content

Commit

Permalink
Merge pull request #1 from CHIPAsia/feature/change_from_session_to_meta
Browse files Browse the repository at this point in the history
Change reliance on session to meta
  • Loading branch information
wzul authored Oct 31, 2023
2 parents 208e23a + 2fa983b commit d167653
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
6 changes: 3 additions & 3 deletions chip-for-givewp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Plugin Name: CHIP for GiveWP
* Plugin URI: https://wordpress.org/plugins/chip-for-givewp/
* Description: CHIP - Better Payment & Business Solutions
* Version: 1.0.3
* Description: CHIP - Digital Finance Platform
* Version: 1.1.0
* Author: Chip In Sdn Bhd
* Author URI: https://www.chip-in.asia
*
Expand All @@ -13,7 +13,7 @@
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/

define( 'GWP_CHIP_MODULE_VERSION', 'v1.0.3');
define( 'GWP_CHIP_MODULE_VERSION', 'v1.1.0');

class Chip_Givewp {

Expand Down
26 changes: 6 additions & 20 deletions includes/class-listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,9 @@ private function handle_processing() {
exit;
}

$payment_id = Give()->session->get( 'chip_id' );
$session_donation_id = Give()->session->get( 'donation_id' );
$payment_id = give_get_meta( $donation_id, '_chip_purchase_id', true, false, 'donation' );

if ( $payment_id ) {
Give()->session->set( 'chip_id', false );
}

if ( $session_donation_id ) {
Give()->session->set( 'donation_id', false );
}

if ( !empty($session_donation_id) && $donation_id != $session_donation_id) {
Chip_Givewp_Helper::log( $donation_id, LogType::ERROR, __( 'Session donation not match with donation id!', 'chip-for-givewp' ) );
give_die( __('Session donation not match with donation id!', 'chip-for-givewp') );
}

if ( empty($payment_id) && isset($_SERVER['HTTP_X_SIGNATURE']) ) {
if ( isset($_SERVER['HTTP_X_SIGNATURE']) ) {
$form_id = give_get_payment_form_id( $donation_id );
$customization = give_get_meta( $form_id, '_give_customize_chip_donations', true );

Expand Down Expand Up @@ -165,10 +151,10 @@ private function handle_processing() {
give_die( __('Unexpected response', 'chip-for-givewp') );
}

if ( give_get_payment_key( $donation_id ) != $payment['reference'] ) {
Chip_Givewp_Helper::log( $donation_id, LogType::ERROR, __('Purchase key does not match!', 'chip-for-givewp'), $payment );
give_die( __('Purchase key does not match!', 'chip-for-givewp'));
}
// if ( give_get_payment_key( $donation_id ) != $payment['reference'] ) {
// Chip_Givewp_Helper::log( $donation_id, LogType::ERROR, __('Purchase key does not match!', 'chip-for-givewp'), $payment );
// give_die( __('Purchase key does not match!', 'chip-for-givewp'));
// }

if ( give_get_payment_total( $donation_id ) != round($payment['purchase']['total'] / 100, give_get_price_decimals( $donation_id )) ) {
Chip_Givewp_Helper::log( $donation_id, LogType::ERROR, __('Payment total does not match!', 'chip-for-givewp'), $payment );
Expand Down
7 changes: 4 additions & 3 deletions includes/class-purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function create( $payment_data ) {
'success_redirect' => $listener->get_redirect_url( array('donation_id' => $donation_id, 'nonce' => $payment_data['gateway_nonce']) ),
'failure_redirect' => $listener->get_redirect_url( array('donation_id' => $donation_id, 'status' => 'error') ),
'creator_agent' => 'GiveWP: ' . GWP_CHIP_MODULE_VERSION,
'reference' => $payment_data['purchase_key'],
'reference' => substr($donation_id,0,128),
'platform' => 'givewp',
'send_receipt' => give_is_setting_enabled( $send_receipt ),
'due' => time() + (absint( $due_strict_timing ) * 60),
Expand Down Expand Up @@ -180,6 +180,8 @@ public function create( $payment_data ) {
$params['client']['zip_code'] = $payment_data['post_data']['card_zip'] ?? '10000';
$params['client']['state'] = substr($payment_data['post_data']['card_state'], 0, 2) ?? 'KL';
}

$params = apply_filters( 'gwp_chip_purchase_params', $params, $payment_data, $this );

$chip = Chip_Givewp_API::get_instance($secret_key, $brand_id);
$payment = $chip->create_payment($params);
Expand All @@ -194,8 +196,7 @@ public function create( $payment_data ) {

Chip_Givewp_Helper::log( $form_id, LogType::HTTP, sprintf( __( 'Create purchases success for donation id %1$s', 'chip-for-givewp' ), $donation_id), $payment );

Give()->session->set('chip_id', $payment['id']);
Give()->session->set('donation_id', $donation_id);
give_update_meta( $donation_id, '_chip_purchase_id', $payment['id'], '', 'donation' );

if ( give_is_test_mode() ) {
give_insert_payment_note( $donation_id, __('This is test environment where payment status is simulated.', 'chip-for-givewp') );
Expand Down
15 changes: 12 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: chipasia, wanzulnet
Tags: chip
Requires at least: 4.7
Tested up to: 6.1
Stable tag: 1.0.3
Tested up to: 6.3
Stable tag: 1.1.0
Requires PHP: 7.1
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand All @@ -14,7 +14,12 @@ CHIP - Better Payment & Business Solutions. Securely accept payment with CHIP fo

This is an official CHIP plugin for GiveWP.

CHIP is a payment and business solutions platform that allow you to securely sell your products and get paid via multiple local and international payment methods.
CHIP is a comprehensive Digital Finance Platform specifically designed to support and empower Micro, Small and Medium Enterprises (MSMEs). We provide a suite of solutions encompassing payment collection, expense management, risk mitigation, and treasury management.

Our aim is to help businesses streamline their financial processes, reduce
operational complexity, and drive growth.

With CHIP, you gain a financial partner committed to simplifying, digitizing, and enhancing your financial operations for ultimate success.

This plugin will enable your GiveWP site to be integrated with CHIP as per documented in [API Documentation](https://developer.chip-in.asia/api#online_purchases_custom_payment_flow_direct_post).

Expand All @@ -27,6 +32,10 @@ This plugin will enable your GiveWP site to be integrated with CHIP as per docum

== Changelog ==

= 1.1.0 - 2023-10-27 =
* Changed - Now the redirection will not rely on session. Instead it will rely on meta.
* Changed - Now reference is set to donation id instead of payment_key

= 1.0.3 - 2023-03-08 =
* Fixed - Donator seeing donation failed page when there is previous failed attempt.

Expand Down

0 comments on commit d167653

Please sign in to comment.