Ich habe ein Problem und hoffe, dass es einige gute Leute hier, die mir helfen können. Ich habe ein Front-End-Formular vorbereitet. Dies ist für ein Spendenformular, und ich habe einen cURL-Anruf hinzugefügt, nachdem das Formular eingereicht hat, an die Zahlung Gateway API. Das Problem hier ist, ich möchte, dass die Formularseite auf eine URL umgeleitet wird, die vom Zahlungsgateway api zurückgegeben wird, damit Benutzer mit ihrer Bank außerhalb bezahlen können.Ändern der Weiterleitung URL nach dem Post Speichern unter Wordpress
Die Idee, die ich habe, ist, den post-Permalink nach dem Post zu speichern, aber bevor Benutzer umgeleitet wird, so dass sie auf die richtige URL weitergeleitet werden (von Payment Gateway API gegeben), und nicht das Original Permalink.
Haben Sie eine Idee, dies auszuführen?
Hier ist mein Code so weit:
<?php
add_action('acf/save_post', 'my_save_post', 10, 1);
function my_save_post($post_id) {
$billplzApi = get_field('billplz_secret_key', 'option');
$billplzId = get_field('billplz_collection_id', 'option');
// bail early if not a donation post
if(get_post_type($post_id) !== 'donation') {
return;
}
// bail early if editing in admin
if(is_admin()) {
return;
}
$post = get_post($post_id);
$amount = '';
$donationGroup = get_field('donation_amount', $post);
$selectedAmount = $donationGroup['select_donation_amount'];
$customAmount = $donationGroup['specify_any_amount'];
if(!$customAmount){
$amount = $selectedAmount;
} else {
$amount = $customAmount;
}
$name = get_field('name', $post);
$email = get_field('email', $post);
$unmobile = get_field('mobile', $post);
$mobile = "+6" . $unmobile;
$billplz_data = array(
'amount' => $amount * 100,
'name' => $name,
'mobile' => $mobile,
'email' => $email,
'collection_id' => $billplzId,
'deliver' => false,
'description' => 'a test for payment gateway',
'redirect_url' => home_url('donation-redirect'),
'callback_url' => home_url('donation-callback')
);
$process = curl_init('https://www.billplz.com/api/v3/bills/');
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $billplzApi . ":");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS,http_build_query($billplz_data));
$return = curl_exec($process);
curl_close($process);
$arr = json_decode($return, true);
//this is the url to replace the original post permalink
$billplz_url = $arr['url'];
}
acf_form_head();
get_header();
?>
<div class="row">
<div class="col-sm-12 col-md-8 col-md-offset-2 col-xs-12">
<?php
while (have_posts()) : the_post();
acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'donation',
'post_status' => 'publish'
),
'submit_value' => 'Donate',
'html_submit_button' => '<input type="submit" class="acf-button btn btn-success btn-lg pull-right" value="%s" />',
'return' => '%post_url%'
));
endwhile;
?>
</div>
</div>
<?php
get_footer();
?>