'Stripe webhook event handler payment_intent.succeeded do not work
Hey im using the example from Stripe and get two errors first i get is in the stripe transactions Webhook feedback pending i think stripe don´t get the http_response_code second error is that the event handler for payment_intent.succeeded does not work
i tried to set http_response_code to the first line but it doesent work also i tried some things with handlePaymentMethodAttached($paymentMethod); but that also did not work
<?php
//require_once __DIR__ . '/lib/stripe-php/init.php';
require 'C:\xampp\htdocs\git\KassenSystemNFC\src\lib\stripe-php\init.php';
// This is your test secret API key.
\Stripe\Stripe::setApiKey('sk_test');
$payload = @file_get_contents('data.json');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object;
// contains a \Stripe\PaymentIntent
// handlePaymentIntentSucceeded($paymentIntent);
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached($paymentMethod);
break;
default:
// Unexpected event type
error_log('Received unknown event type');
}
echo 'test3';
http_response_code(200);
?>
Some test Data:
{
"id": "pi_3KkTcKFZ1SldCNdl1oQ6EHua",
"object": "payment_intent",
"last_payment_error": null,
"livemode": false,
"next_action": null,
"status": "succeeded",
"amount": 2000,
"amount_capturable": 0,
"amount_received": 2000,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
{
"id": "ch_3KkTcKFZ1SldCNdl1ykUc1k1",
"object": "charge",
"amount": 2000,
"amount_captured": 2000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_3KkTcKFZ1SldCNdl1vEtX15n",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": null,
"name": null,
"phone": null
},
"calculated_statement_descriptor": "Stripe",
"captured": true,
"created": 1648993040,
"currency": "usd",
"customer": null,
"description": "(created by Stripe CLI)",
"destination": null,
"dispute": null,
"disputed": false,
"failure_balance_transaction": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": null,
"livemode": false,
"metadata": {
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 26,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_3KkTcKFZ1SldCNdl1oQ6EHua",
"payment_method": "pm_1KkTcKFZ1SldCNdlD2owNokC",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": null
},
"country": "US",
"exp_month": 4,
"exp_year": 2023,
"fingerprint": "gAXCwgiie4sj07Q2",
"funding": "credit",
"installments": null,
"last4": "4242",
"mandate": null,
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1Kk3QuFZ1SldCNdl/ch_3KkTcKFZ1SldCNdl1ykUc1k1/rcpt_LRMLp2vbqspWLy6cIp8TJALI7D2X3Yj",
"refunded": false,
"refunds": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_3KkTcKFZ1SldCNdl1ykUc1k1/refunds"
},
"review": null,
"shipping": {
"address": {
"city": "San Francisco",
"country": "US",
"line1": "510 Townsend St",
"line2": null,
"postal_code": "94103",
"state": "CA"
},
"carrier": null,
"name": "Jenny Rosen",
"phone": null,
"tracking_number": null
},
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_3KkTcKFZ1SldCNdl1oQ6EHua"
},
"client_secret": "pi_3KkTcKFZ1SldCNdl1oQ6EHua_secret_YwhpCBalyavlHWjdVT0YQwIEn",
"confirmation_method": "automatic",
"created": 1648993040,
"currency": "usd",
"customer": null,
"description": "(created by Stripe CLI)",
"invoice": null,
"metadata": {
},
"on_behalf_of": null,
"payment_method": "pm_1KkTcKFZ1SldCNdlD2owNokC",
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": {
"address": {
"city": "San Francisco",
"country": "US",
"line1": "510 Townsend St",
"line2": null,
"postal_code": "94103",
"state": "CA"
},
"carrier": null,
"name": "Jenny Rosen",
"phone": null,
"tracking_number": null
},
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"transfer_data": null,
"transfer_group": null
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
