Skip to content

Commit cf23f80

Browse files
committed
Add Custom fields to Paystack Trasaction
1 parent b855dc9 commit cf23f80

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

public/class-paystack-forms-public.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,25 @@ function paystack_submit_action() {
338338
'code' => $insert['txn_code'],
339339
'email' => $insert['email'],
340340
'total' => $insert['amount']*100,
341+
'custom_fields' => paystack_meta_as_custom_fields($metadata)
341342
);
342343
echo json_encode($response);
343344

344345
die();
345346
}
346347

348+
function paystack_meta_as_custom_fields($metadata){
349+
$custom_fields = [];
350+
foreach ($metadata as $key => $value) {
351+
$custom_fields[] = [
352+
'display_name' => ucwords(str_replace("_", " ", $key)),
353+
'variable_name' => $key,
354+
'value' => $value
355+
];
356+
}
357+
return $custom_fields;
358+
}
359+
347360
add_action( 'wp_ajax_paystack_confirm_payment', 'paystack_confirm_payment' );
348361
add_action( 'wp_ajax_nopriv_paystack_confirm_payment', 'paystack_confirm_payment' );
349362
function paystack_confirm_payment() {

public/js/paystack-forms-public.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
email: data.email,
8686
amount: data.total,
8787
ref: data.code,
88+
metadata: {'custom_fields': data.custom_fields},
8889
callback: function(response){
8990
$.blockUI({ message: 'Please wait...' });
9091
$.post($form.attr('action'), {'action':'paystack_confirm_payment','code':response.trxref}, function(newdata) {

0 commit comments

Comments
 (0)