Im trying to sell videos on my website, hosted using wordpress. I have set up a Stripe account and been using "WP Simple Pay Lite for Stripe" Plugin on my website.
The problem that i'm facing is when I get a payment on stripe I manually send my customers the video that they have purchased. I was wondering if anyone has any advice on how I can automate the process by sending my customers the product once payment has been paid.
For this "WP Simple Pay Lite for Stripe" Plugin there is a successful payment URL redirect feature. That I was using before. How ever I noticed that you can view the successful payment redirect from the Developer Tools.
<input type="hidden" name="sc-redirect" value="https://wpsimplepay.com/demo-success-page/">
As Stanimir Stoyanov said, you can use sc_after_charge
but his code won't work because sc_after_charge
returns Charge
object, not 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' );
Here we first check if payment was successful, if yes, we the email the file to the user :)
If you plan to sell multiple products... You can set appropriate description and send different files for different descriptions accessible by $response->description
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments