Skip to content

Commit 52ffd8e

Browse files
committed
Merchant transaction_charge option
1 parent 2ca24ae commit 52ffd8e

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

public/class-paystack-forms-public.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,9 @@ function kkd_pff_paystack_submit_action() {
11021102
$recur = get_post_meta($_POST["pf-id"],'_recur',true);
11031103
$subaccount = get_post_meta($_POST["pf-id"],'_subaccount',true);
11041104
$txnbearer = get_post_meta($_POST["pf-id"],'_txnbearer',true);
1105-
1105+
$transaction_charge = get_post_meta($_POST["pf-id"],'_merchantamount',true);
1106+
$transaction_charge = $transaction_charge*100;
1107+
11061108
$txncharge = get_post_meta($_POST["pf-id"],'_txncharge',true);
11071109
$minimum = get_post_meta($_POST["pf-id"],'_minimum',true);
11081110
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);//User input
@@ -1279,7 +1281,14 @@ function kkd_pff_paystack_submit_action() {
12791281
kkd_pff_paystack_send_invoice($currency,$insert['amount'],$fullname,$insert['email'],$code);
12801282
}
12811283
}
1282-
1284+
if ($subaccount == "" || !isset($subaccount)) {
1285+
$subaccount = NULL;
1286+
$txnbearer = NULL;
1287+
$transaction_charge = NULL;
1288+
}
1289+
if ($transaction_charge == "" || $transaction_charge == 0 || $transaction_charge == NULL) {
1290+
$transaction_charge = NULL;
1291+
}
12831292
$response = array(
12841293
'result' => 'success',
12851294
'code' => $insert['txn_code'],
@@ -1290,7 +1299,8 @@ function kkd_pff_paystack_submit_action() {
12901299
'total' => $insert['amount']*100,
12911300
'custom_fields' => $fixedmetadata,
12921301
'subaccount' => $subaccount,
1293-
'txnbearer' => $txnbearer
1302+
'txnbearer' => $txnbearer,
1303+
'transaction_charge' => $transaction_charge
12941304
);
12951305
echo json_encode($response);
12961306

@@ -1502,6 +1512,10 @@ function kkd_pff_paystack_retry_action() {
15021512
$wpdb->update( $table, array( 'txn_code_2' => $newcode),array('txn_code' => $code));
15031513

15041514
$currency = get_post_meta($dbdata->post_id,'_currency',true);
1515+
$subaccount = get_post_meta($dbdata->post_id,'_subaccount',true);
1516+
$txnbearer = get_post_meta($dbdata->post_id,'_txnbearer',true);
1517+
$transaction_charge = get_post_meta($dbdata->post_id,'_merchantamount',true);
1518+
$transaction_charge = $transaction_charge*100;
15051519
$fixedmetadata = kkd_pff_paystack_meta_as_custom_fields($dbdata->metadata);
15061520
$nmeta = json_decode($dbdata->metadata);
15071521
foreach ($nmeta as $nkey => $nvalue) {
@@ -1514,7 +1528,14 @@ function kkd_pff_paystack_retry_action() {
15141528
}
15151529

15161530
}
1517-
1531+
if ($subaccount == "" || !isset($subaccount)) {
1532+
$subaccount = NULL;
1533+
$txnbearer = NULL;
1534+
$transaction_charge = NULL;
1535+
}
1536+
if ($transaction_charge == "" || $transaction_charge == 0 || $transaction_charge == NULL || !isset($transaction_charge)) {
1537+
$transaction_charge = NULL;
1538+
}
15181539
$response = array(
15191540
'result' => 'success',
15201541
'code' => $newcode,
@@ -1523,7 +1544,10 @@ function kkd_pff_paystack_retry_action() {
15231544
'email' => $dbdata->email,
15241545
'name' => $fullname,
15251546
'total' => $dbdata->amount*100,
1526-
'custom_fields' => $fixedmetadata
1547+
'custom_fields' => $fixedmetadata,
1548+
'subaccount' => $subaccount,
1549+
'txnbearer' => $txnbearer,
1550+
'transaction_charge' => $transaction_charge
15271551
);
15281552
echo json_encode($response);
15291553

public/js/paystack-forms-public.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
lastname: lastName,
158158
subaccount:data.subaccount,
159159
bearer:data.txnbearer,
160+
transaction_charge:data.transaction_charge,
160161
ref: data.code,
161162
metadata: {'custom_fields': data.custom_fields},
162163
callback: function(response){
@@ -199,6 +200,7 @@
199200
ref: data.code,
200201
subaccount:data.subaccount,
201202
bearer:data.txnbearer,
203+
transaction_charge:data.transaction_charge,
202204
metadata: {'custom_fields': data.custom_fields},
203205
callback: function(response){
204206
$.blockUI({ message: 'Please wait...' });
@@ -277,7 +279,10 @@
277279
firstname: firstName,
278280
lastname: lastName,
279281
ref: data.code,
280-
metadata: {'custom_fields': data.custom_fields},
282+
subaccount:data.subaccount,
283+
bearer:data.txnbearer,
284+
transaction_charge:data.transaction_charge,
285+
metadata: {'custom_fields': data.custom_fields},
281286
callback: function(response){
282287
$.blockUI({ message: 'Please wait...' });
283288
$.post($form.attr('action'), {'action':'kkd_pff_paystack_rconfirm_payment','code':response.trxref,'quantity':quantity}, function(newdata) {
@@ -316,7 +321,10 @@
316321
firstname: firstName,
317322
lastname: lastName,
318323
ref: data.code,
319-
metadata: {'custom_fields': data.custom_fields},
324+
subaccount:data.subaccount,
325+
bearer:data.txnbearer,
326+
transaction_charge:data.transaction_charge,
327+
metadata: {'custom_fields': data.custom_fields},
320328
callback: function(response){
321329
$.blockUI({ message: 'Please wait...' });
322330
$.post($form.attr('action'), {'action':'kkd_pff_paystack_rconfirm_payment','code':response.trxref}, function(newdata) {

0 commit comments

Comments
 (0)