Skip to content

Commit fd7a888

Browse files
authored
Merge pull request #2 from ibrahimlawal/master
A fix and a feature
2 parents 602dff7 + cf23f80 commit fd7a888

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

public/class-paystack-forms-public.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,25 @@ function paystack_submit_action() {
340340
'code' => $insert['txn_code'],
341341
'email' => $insert['email'],
342342
'total' => $insert['amount']*100,
343+
'custom_fields' => paystack_meta_as_custom_fields($metadata)
343344
);
344345
echo json_encode($response);
345346

346347
die();
347348
}
348349

350+
function paystack_meta_as_custom_fields($metadata){
351+
$custom_fields = [];
352+
foreach ($metadata as $key => $value) {
353+
$custom_fields[] = [
354+
'display_name' => ucwords(str_replace("_", " ", $key)),
355+
'variable_name' => $key,
356+
'value' => $value
357+
];
358+
}
359+
return $custom_fields;
360+
}
361+
349362
add_action( 'wp_ajax_paystack_confirm_payment', 'paystack_confirm_payment' );
350363
add_action( 'wp_ajax_nopriv_paystack_confirm_payment', 'paystack_confirm_payment' );
351364
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)