2017-12-15 34 views
2

私は問題があり、私に助けてくれる人がいることを願っています。私はフロントエンドフォームを用意しました。これは寄付用フォームであり、フォームが送信された後にcURLコールを支払いゲートウェイapiに追加しました。ここでの問題は、フォームページを支払いゲートウェイAPIによって返されたURLにリダイレクトして、ユーザーがオフサイトの銀行で支払いを受けるようにすることです。Wordpressで保存後のリダイレクトURLを変更する

投稿が保存された後で、ユーザーがリダイレクトされる前にpost permalinkを変更して、元のものではなく正しいURL(支払いゲートウェイapiで指定)にリダイレクトされるようにするというアイデアは、 permalink。

これを実行するためのアイデアはありますか?

ここでは、これまでに私のコードです:

ここで、この問題に対する解決策が見つかり
<?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(); 

?> 

答えて