#saumil

1 messages · Page 1 of 1 (latest)

compact zealotBOT
primal prawn
orchid plover
#

i am using webhook for intent payment can i use subscription payment and invoice.paid event in this hook, how to use in this code please suggest me code is
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_UJ3nS0qMSkUzimPogcker0Sk34b';
            $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->write_log( $paymentIntent );

    }
primal prawn
#

Your code currently listening to payment_intent.succeeded event only in:

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

The steps for listening invoice.paid event will be:

  1. In the Webhook configuration in the Dashboard, you should enable listening to invoice.paid event (See screenshot)
  2. In your code, add another invoice.paid condition to handle the action you intend to achieve. For example,
                if ( $event->type == 'invoice.paid' ) {
                    $invoice = $event->data->object;
                    // action to perform on $invoice
                }
orchid plover
#

i am created js code but i am not sure how listen invoice paid and subscription created agains createCardPayment
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.');
// Show a success message to your customer
// There's a risk of the customer closing the window before callback
// execution. Set up a webhook or plugin to listen for the
// payment_intent.succeeded event that handles any business critical
// post-payment actions.
}
// if(response.success){
// window.location.href = "https://dev.nirmoh.com.au/success/";
// }
}
});

        },
primal prawn
#

invoice.paid event is asynchronous using Webhooks and it won't be available in createCardPayment

orchid plover
#

my response is this so error fire in console

primal prawn
#

What is the value of your response parameter? It looks like the value is a subscription ID instead of client secret (pi_xxx_secret_xxx)

orchid plover
#

yes value is subscription id so how to match with subscription id

primal prawn
compact zealotBOT