#saumil

1 messages · Page 1 of 1 (latest)

pliant obsidianBOT
forest bobcat
#

Sorry, you'll need to share the specific part of the code you're having issues with

#

You've just dumped 800+ lines of code. We don't have time to work through all that

golden vector
#

$.ajax({
type : "POST",
dataType : "json",
cache: false,
contentType: false,
processData: false,
url : my_ajax_object.ajax_url,
data : formData,//data,
success: function(response) {
that.prop('disabled', false);
stripe.confirmCardPayment(response, {
payment_method: {
card: card,
billing_details: {
name: 'Jenny Rosen'
}
}
}).then(function(result) {
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
window.location.href = "https://dev.nirmoh.com.au/failed/";
console.log(result.error.message);
} else {

                    if (result.paymentIntent.status === 'succeeded') {
                        console.log("Success");
                        window.location.href = "https://dev.nirmoh.com.au/success/";
                        
                       
                    }
                  
                }
            });

        },
#

this is ajax

#

this is webhook
public function okt_stripe_event_listener() {

        if ( isset( $_GET['webhook-listener'] ) && $_GET['webhook-listener'] == 'stripe' ) {
            global $stripe_options;
            $payload         = @file_get_contents( 'php://input' );
            $sig_header      = $_SERVER['HTTP_STRIPE_SIGNATURE'];
            $endpoint_secret = 'whsec_UJ3nS0qMSkUzimPogcker0Sk34bHdUP7';
            $event           = null;

            try {
                $event = \Stripe\Webhook::constructEvent(
                    $payload, $sig_header, $endpoint_secret
                );
            } catch ( \UnexpectedValueException $e ) {
                // Invalid payload
                http_response_code( 400 );
                exit();
            } catch ( \Stripe\Exception\SignatureVerificationException $e ) {
                // Invalid signature
                http_response_code( 400 );
                exit();
            }

            if ( $event->type == 'payment_intent.succeeded' ) {
                $paymentIntent = $event->data->object;
                $this->handleCompletedCheckoutSession( $paymentIntent );
            }
            else if ( $event->type == 'invoice.paid' ) {
                $invoice = $event->data->object;
                $this->handleCompletedInvoiceSession( $invoice );
            }
            else if ( $event->type == 'customer.subscription.created' ) {
                $paymentIntent = $event->data->object;
                $this->handleCompletedCheckoutSession( $paymentIntent );
            }

            http_response_code( 200 );
        }

    }
forest bobcat
#

Ok, and what's the specific issue?

golden vector
#

subscription done and response 200 but page not redirect to succes page

pliant obsidianBOT
forest bobcat
#

What is the success page in this instance?

#

Where is that redirect called in your code?

golden vector
#

public function okt_stripe_event_listener() {

        if ( isset( $_GET['webhook-listener'] ) && $_GET['webhook-listener'] == 'stripe' ) {
            global $stripe_options;
            $payload         = @file_get_contents( 'php://input' );
            $sig_header      = $_SERVER['HTTP_STRIPE_SIGNATURE'];
            $endpoint_secret = 'whsec_UJ3nS0qMSkUzimPogcker0Sk34bHdUP7';
            $event           = null;

            try {
                $event = \Stripe\Webhook::constructEvent(
                    $payload, $sig_header, $endpoint_secret
                );
            } catch ( \UnexpectedValueException $e ) {
                // Invalid payload
                http_response_code( 400 );
                exit();
            } catch ( \Stripe\Exception\SignatureVerificationException $e ) {
                // Invalid signature
                http_response_code( 400 );
                exit();
            }

            if ( $event->type == 'payment_intent.succeeded' ) {
                $paymentIntent = $event->data->object;
                $this->handleCompletedCheckoutSession( $paymentIntent );
            }
            
            

            http_response_code( 200 );
        }

    }

    public function handleCompletedCheckoutSession( $paymentIntent ) {
        $manage_donations = Okt_Manage_Donations::get_instance();
        $paymentIntentId= $paymentIntent['id'];
        $this->write_log( "Fulfilling order..." );
        $manage_donations->update_donation(array('status' => 'completed'));
        
    }

this is th webhook for payment done

#

and this is the ajax to response and redirect url
$.ajax({
type : "POST",
dataType : "json",
cache: false,
contentType: false,
processData: false,
url : my_ajax_object.ajax_url,
data : formData,//data,
success: function(response) {
that.prop('disabled', false);
stripe.confirmCardPayment(response, {
payment_method: {
card: card,
billing_details: {
name: 'Jenny Rosen'
}
}
}).then(function(result) {
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
window.location.href = "https://dev.nirmoh.com.au/failed/";
console.log(result.error.message);
} else {
// The payment has been processed!
if (result.paymentIntent.status === 'succeeded') {
console.log("Success");
window.location.href = "https://dev.nirmoh.com.au/success/";
// $('#payment-status').html('Payment succeeded! <a href="https://dev.nirmoh.com.au/success/">Click here</a> to go to the success page.');

                }
            });
elfin tartan
#

Hi! I'm taking over this thread.

#

You are sharing a lot of code. Can you explain with words what you are trying to do, and the exact issue you are facing?

#

First of all, how are you creating the subscription? With a Checkout Session or the Subscription endpoint directly?

golden vector
#

i am creating subscription using $stripe->subscriptions->create() after fill card details click submit ajax running and return 200 and aslo subscription done in my stripe dashboard but page stuck in card details page and not rediredt to success page , i am developers so i am checking in ajax but user not find any response in front end so he will countinu click in submit and every time ajax call and many time subscription created. thats my problem

elfin tartan
#

Are you using the Payment Element on the frontend to collect card details?

pliant obsidianBOT