2016-11-15 69 views
1

我試圖在我的網站上銷售視頻,使用wordpress託管。我已經建立了一個Stripe賬戶,並在我的網站上使用了「WP Simple Pay Lite for Stripe」插件。如何在條形支付後訪問響應/重定向?

我面臨的問題是當我在條紋上獲得付款時,我會手動向我的客戶發送他們購買的視頻。我想知道是否有人對我如何通過在支付款項後向我的客戶發送產品來實現流程自動化提出任何建議。

對於此「WP Simple Pay Lite for Stripe」插件,您可以獲得成功的支付URL重定向功能。我以前使用過。我曾經注意到,您可以從開發者工具中查看成功的付款重定向。

<input type="hidden" name="sc-redirect" value="https://wpsimplepay.com/demo-success-page/">

+0

你想隱藏這個成功的網址? –

回答

3

作爲斯坦尼米爾斯托亞諾夫說你可以使用sc_after_charge,但他的代碼將不會工作,因爲sc_after_charge返回Charge對象,而不是JSON。

/** 
* Sends video url to customer when payment is successful 
* @param $response \Stripe\Charge 
*/ 
function send_video_if_payment_successful($response) { 
    if ($response->paid) { 
     // Maybe check amount and or description to ensure it's same product 
     $file = 'http://url_to/file_to_attach.mp4'; // Video url 
     $subject = 'Find your video here - My store'; // Email subject 
     $msg = ' 
     Thanks for buying... 
     yada yada yada... 
     Please find attached video.'; // Email message 

     $attachments = array($file); // Add attachment 

     $headers = 'From: My store <[email protected]>' . "\r\n"; // Set yourself in From header 

     wp_mail($response->receipt_email, $subject, $msg, $headers, $attachments); // Send the mail 
    } 
} 
add_action('sc_after_charge', 'send_video_if_payment_successful'); 

在這裏,我們首先檢查是否付款成功,如果是的話,我們的電子郵件的文件給用戶:)

如果您打算出售多種產品...您可以設置適當的說明,併發送用於訪問不同的描述不同的文件由$response->description

+0

這樣我們也不會將網址暴露給我們網站上的視頻...;) – shramee

+0

謝謝你的工作就像一個魅力。 –

4

this topic其類似於你的作者建議使用sc_after_charge鉤。所以,你的代碼將是:

add_action('sc_after_charge', 'sc_after_charge_example'); 
function sc_after_charge_example($charge_response) { 
    if ($charge_response->paid) { 
     $url = 'https://wpsimplepay.com/demo-success-page/'; 

     wp_redirect($url); 
     exit; 
    } 
} 

我不知道阿布響應類型,如果它的JSON,但在Stripe Docs它是一個JSON。