#saumil
1 messages · Page 1 of 1 (latest)
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
$.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 );
}
}
Ok, and what's the specific issue?
subscription done and response 200 but page not redirect to succes page
What is the success page in this instance?
Where is that redirect called in your code?
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.');
}
});
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?
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
Are you using the Payment Element on the frontend to collect card details?
When you confirm the PaymentIntent on the frontend, set the return_url. And the user will be automatically redirected to your page after the payment is successful. https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-return_url