#Wakko-payments
1 messages ยท Page 1 of 1 (latest)
You can get this information by expanding payment_method for the request. You can read more about expansion here: https://stripe.com/docs/expand
Thank you very much I will read into it
I get the following error: <b>Fatal error</b>: Uncaught Stripe\Error\InvalidRequest: This property cannot be expanded (payment_intent).
What does your expansion code look like?
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount($json_obj->items),
'currency' => 'usd',
'expand' => ['payment_intent.payment_method'],
]);
You need to do this instead:
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount($json_obj->items),
'currency' => 'usd',
'expand' => ['payment_method'],
]);
Thank you, it runs now but im not seeing the card type (credit/debit)
{
"id": "pi_3Jek56KIzsM95yHa1KZoY2HN",
"object": "payment_intent",
"amount": 1400,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"client_secret": "pi_3Jek56KIzsM95yHa1KZoY2HN_secret_29zkWRBJscpWBTaD4pHjTPZLP",
"confirmation_method": "automatic",
"created": 1632850024,
"currency": "usd",
"description": null,
"last_payment_error": null,
"livemode": false,
"next_action": null,
"payment_method": "pm_1Jek5vKIzsM95yHaOOAdDKLD",
"payment_method_types": [
"card"
],
"receipt_email": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"status": "succeeded"
}
this is what I get
Is that the response from the creation request, or from confirmation?
from the comfirmation I think
Ah, that's the issue then - expansion is per-request, so you need to specify it for the confirmation request as well
Sorry I dont understand
When you specified 'expand' => ['payment_method'], in your request to create the Payment Intent that expanded payment_method for that specific request. At a later point, you then made an entirely new request client-side to confirm that same Payment Intent. That client-side request also needs to be expanded.
you mean here in the javascript?
// The items the customer wants to buy
var purchase = {
items: [{ id: "xl-tshirt" }]
};
// Disable the button until we have Stripe set up on the page
document.querySelector("button").disabled = true;
fetch("../create.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(purchase)
})
Can you show us the code you're using to confirm the Payment Intent? What you sent over is just your code that calls to your own backend to create the Payment Intent
<?php
require 'vendor/autoload.php';
// This is your real test secret API key.
\Stripe\Stripe::setApiKey('sk_test_xxxxxxxxxxxxxxxxxxxxxxxxx');
function calculateOrderAmount(array $items): int {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// customers from directly manipulating the amount on the client
return 1400;
}
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount($json_obj->items),
'currency' => 'usd',
'expand' => ['payment_method'],
]);
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
==========================
this one?
Hello! I'm taking over for @noble fractal, let me get caught up. ๐
sure thank you
Ah, okay, we need your JavaScript code, not your PHP code. The JavaScript from your website.
Lines 64-69 have this:
stripe
.confirmCardPayment(clientSecret, {
payment_method: {
card: card
}
})
You need to add expansion there, like this:
stripe
.confirmCardPayment(clientSecret, {
payment_method: {
card: card
},
expand: ['payment_method']
})
Great thank you very much it works now, I can see the funding
another question
is it posible to remove the zip code from the card form?
Yep, you can use hidePostalCode on the Card Element: https://stripe.com/docs/js/elements_object/create_element?type=card#elements_create-options-hidePostalCode