The JAVA Noob
The JAVA Noob

Reputation: 367

How to access the response/redirect after stripe payment?

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/">

Upvotes: 1

Views: 3822

Answers (4)

Dipen Desai
Dipen Desai

Reputation: 149

please use woocommerce download product

https://docs.woocommerce.com/document/digitaldownloadable-product-handling/

check this i hope it is helpfull

Upvotes: 1

Stanimir Stoyanov
Stanimir Stoyanov

Reputation: 1916

In this topic which is similar to yours the author suggests to use sc_after_charge hook. So your code will be:

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;
    }
}

I am not sure abou the response type and if its JSON, but in Stripe Docs it's a JSON.

Upvotes: 4

shramee
shramee

Reputation: 5099

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

Upvotes: 3

kayleighsdaddy
kayleighsdaddy

Reputation: 660

In the short code add success_redirect_url="https://wpsimplepay.com/demo-success-page" as an attribute

[stripe name="My Store" description="My Product" amount="1999" success_redirect_url="https://wpsimplepay.com/demo-success-page"]

Source: https://wpsimplepay.com/docs/shortcodes/stripe-checkout/

Upvotes: 1

Related Questions