Skip to content

Commit f27efbc

Browse files
Version 5.7.5 Release (#80)
Co-authored-by: gertrude-paystack <110245619+gertrude-paystack@users.noreply.github.com>
1 parent bb47e6d commit f27efbc

9 files changed

Lines changed: 265 additions & 199 deletions

assets/images/paystack-ke.png

11 KB
Loading

assets/js/paystack.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ jQuery( function( $ ) {
171171

172172
let amount = Number( wc_paystack_params.amount );
173173

174-
let paystack_callback = function( response ) {
175-
$form.append( '<input type="hidden" class="paystack_txnref" name="paystack_txnref" value="' + response.trxref + '"/>' );
174+
let paystack_callback = function( transaction ) {
175+
$form.append( '<input type="hidden" class="paystack_txnref" name="paystack_txnref" value="' + transaction.reference + '"/>' );
176176
paystack_submit = true;
177177

178178
$form.submit();
@@ -195,14 +195,14 @@ jQuery( function( $ ) {
195195
amount: amount,
196196
ref: wc_paystack_params.txnref,
197197
currency: wc_paystack_params.currency,
198-
callback: paystack_callback,
199198
subaccount: subaccount_code,
200199
bearer: charges_account,
201200
transaction_charge: transaction_charges,
202201
metadata: {
203202
custom_fields: wcPaystackCustomFields(),
204203
},
205-
onClose: function() {
204+
onSuccess: paystack_callback,
205+
onCancel: () => {
206206
$( '#wc-paystack-form' ).show();
207207
$( this.el ).unblock();
208208
}
@@ -215,12 +215,8 @@ jQuery( function( $ ) {
215215
}
216216
}
217217

218-
let handler = PaystackPop.setup( paymentData );
219-
220-
handler.openIframe();
221-
222-
return false;
223-
218+
const paystack = new PaystackPop();
219+
paystack.newTransaction( paymentData );
224220
}
225221

226222
} );

assets/js/paystack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-wc-gateway-custom-paystack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ public function payment_scripts() {
587587
}
588588
}
589589

590-
update_post_meta( $order_id, '_paystack_txn_ref', $txnref );
591-
590+
$order->update_meta_data( '_paystack_txn_ref', $txnref );
591+
$order->save();
592592
}
593593

594594
wp_localize_script( 'wc_paystack', 'wc_paystack_params', $paystack_params );

includes/class-wc-gateway-paystack-subscriptions.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ public function process_subscription_payment( $order, $amount ) {
9797

9898
$order_id = $order->get_id();
9999

100-
$auth_code = get_post_meta( $order_id, '_paystack_token', true );
100+
$paystack_token = $order->get_meta( '_paystack_token' );
101101

102-
if ( $auth_code ) {
102+
if ( ! empty( $paystack_token ) ) {
103103

104104
$order_amount = $amount * 100;
105+
$txnref = $order_id . '_' . time();
106+
107+
$order->update_meta_data( '_paystack_txn_ref', $txnref );
108+
$order->save();
105109

106110
$paystack_url = 'https://api.paystack.co/transaction/charge_authorization';
107111

@@ -112,11 +116,21 @@ public function process_subscription_payment( $order, $amount ) {
112116

113117
$metadata['custom_fields'] = $this->get_custom_fields( $order_id );
114118

119+
if ( strpos( $paystack_token, '###' ) !== false ) {
120+
$payment_token = explode( '###', $paystack_token );
121+
$auth_code = $payment_token[0];
122+
$customer_email = $payment_token[1];
123+
} else {
124+
$auth_code = $paystack_token;
125+
$customer_email = $order->get_billing_email();
126+
}
127+
115128
$body = array(
116-
'email' => $order->get_billing_email(),
129+
'email' => $customer_email,
117130
'amount' => $order_amount,
118131
'metadata' => $metadata,
119132
'authorization_code' => $auth_code,
133+
'reference' => $txnref,
120134
);
121135

122136
$args = array(

0 commit comments

Comments
 (0)