Skip to content

Commit f60aed2

Browse files
committed
fix error with missing payment method
1 parent d9580b1 commit f60aed2

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

src/Message/PaymentIntents/ConfirmPaymentIntentRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function getData()
3737
$data['return_url'] = $this->getReturnUrl();
3838
}
3939

40+
if ($this->getPaymentMethod()) {
41+
$data['payment_method'] = $this->getPaymentMethod();
42+
}
43+
4044
return $data;
4145
}
4246

tests/Message/PaymentIntents/ConfirmPaymentIntentRequestTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
class ConfirmPaymentIntentRequestTest extends TestCase
88
{
9+
/**
10+
* @var ConfirmPaymentIntentRequest
11+
*/
12+
protected $request;
13+
914
public function setUp()
1015
{
1116
$this->request = new ConfirmPaymentIntentRequest($this->getHttpClient(), $this->getHttpRequest());
@@ -69,4 +74,25 @@ public function testConfirm3dsRedirect()
6974
$this->assertSame('pm_1Ev1LzFSbr6xR4YA0TZ8jta0', $response->getCardReference());
7075
}
7176

77+
public function testConfirm3dsRedirectMayReturnError()
78+
{
79+
$this->setMockHttpResponse('ConfirmIntentMissingPaymentMethod.txt');
80+
$response = $this->request->send();
81+
82+
$this->assertFalse($response->isSuccessful());
83+
$this->assertFalse($response->isRedirect());
84+
$this->assertSame(
85+
"You cannot confirm this PaymentIntent because it's missing a payment method. " .
86+
"To confirm the PaymentIntent with cus_G0fHJ1TaSxY7lF, specify a payment method attached " .
87+
"to this customer along with the customer ID.",
88+
$response->getMessage()
89+
);
90+
}
91+
92+
public function testConfirm3dsWithPaymentMethod()
93+
{
94+
$this->request->setPaymentMethod('card_1FUdwaG3M98oE4tV2O1uDpvH');
95+
$data = $this->request->getData();
96+
$this->assertSame('card_1FUdwaG3M98oE4tV2O1uDpvH', $data['payment_method']);
97+
}
7298
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
HTTP/1.1 400 Bad Request
2+
Server: nginx
3+
Date: Sun, 17 Oct 2019 19:51:15 GMT
4+
Content-Type: application/json;charset=utf-8
5+
Content-Length: 3674
6+
Connection: keep-alive
7+
Cache-Control: no-cache, no-store
8+
Access-Control-Max-Age: 300
9+
Access-Control-Allow-Credentials: true
10+
11+
{
12+
"error": {
13+
"code": "payment_intent_unexpected_state",
14+
"doc_url": "https://stripe.com/docs/error-codes/payment-intent-unexpected-state",
15+
"message": "You cannot confirm this PaymentIntent because it's missing a payment method. To confirm the PaymentIntent with cus_G0fHJ1TaSxY7lF, specify a payment method attached to this customer along with the customer ID.",
16+
"payment_intent": {
17+
"id": "pi_1FUdwbG3M98oE4tVVQMhEldb",
18+
"object": "payment_intent",
19+
"amount": 7000,
20+
"amount_capturable": 0,
21+
"amount_received": 0,
22+
"application": null,
23+
"application_fee_amount": null,
24+
"canceled_at": null,
25+
"cancellation_reason": null,
26+
"capture_method": "automatic",
27+
"charges": {
28+
"object": "list",
29+
"data": [
30+
],
31+
"has_more": false,
32+
"total_count": 0,
33+
"url": "/v1/charges?payment_intent=pi_1FUdwbG3M98oE4tVVQMhEldb"
34+
},
35+
"client_secret": "pi_1FUdwbG3M98oE4tVVQMhEldb_secret_PY30Txaeht6iqEUsWjqqQ1yY1",
36+
"confirmation_method": "manual",
37+
"created": 1571337809,
38+
"currency": "usd",
39+
"customer": "cus_G0fHJ1TaSxY7lF",
40+
"description": null,
41+
"invoice": null,
42+
"last_payment_error": {
43+
"code": "payment_intent_authentication_failure",
44+
"doc_url": "https://stripe.com/docs/error-codes/payment-intent-authentication-failure",
45+
"message": "The provided PaymentMethod has failed authentication. You can provide payment_method_data or a new PaymentMethod to attempt to fulfill this PaymentIntent again.",
46+
"payment_method": {
47+
"id": "card_1FUdwaG3M98oE4tV2O1uDpvH",
48+
"object": "payment_method",
49+
"billing_details": {
50+
"address": {
51+
"city": "New Jersey",
52+
"country": "US",
53+
"line1": "New Jersey Turnpike",
54+
"line2": null,
55+
"postal_code": "00701",
56+
"state": "NJ"
57+
},
58+
"email": null,
59+
"name": "Brad Fitz",
60+
"phone": null
61+
},
62+
"card": {
63+
"brand": "visa",
64+
"checks": {
65+
"address_line1_check": "pass",
66+
"address_postal_code_check": "pass",
67+
"cvc_check": "pass"
68+
},
69+
"country": "IE",
70+
"exp_month": 11,
71+
"exp_year": 2023,
72+
"fingerprint": "Cb549Jvs1wPUfTWb",
73+
"funding": "credit",
74+
"generated_from": null,
75+
"last4": "3220",
76+
"three_d_secure_usage": {
77+
"supported": true
78+
},
79+
"wallet": null
80+
},
81+
"created": 1571337808,
82+
"customer": "cus_G0fHJ1TaSxY7lF",
83+
"livemode": false,
84+
"metadata": {
85+
},
86+
"type": "card"
87+
},
88+
"type": "invalid_request_error"
89+
},
90+
"livemode": false,
91+
"metadata": {
92+
},
93+
"next_action": null,
94+
"on_behalf_of": null,
95+
"payment_method": null,
96+
"payment_method_options": {
97+
"card": {
98+
"installments": null,
99+
"request_three_d_secure": "automatic"
100+
}
101+
},
102+
"payment_method_types": [
103+
"card"
104+
],
105+
"receipt_email": null,
106+
"review": null,
107+
"setup_future_usage": null,
108+
"shipping": null,
109+
"source": null,
110+
"statement_descriptor": null,
111+
"statement_descriptor_suffix": null,
112+
"status": "requires_payment_method",
113+
"transfer_data": null,
114+
"transfer_group": null
115+
},
116+
"type": "invalid_request_error"
117+
}
118+
}

0 commit comments

Comments
 (0)