#Wakko-payments

1 messages ยท Page 1 of 1 (latest)

noble fractal
#

You can get this information by expanding payment_method for the request. You can read more about expansion here: https://stripe.com/docs/expand

Learn how to reduce the number of requests you make to the Stripe API by expanding objects in responses.

dry river
#

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).

noble fractal
#

What does your expansion code look like?

dry river
#

$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount($json_obj->items),
'currency' => 'usd',
'expand' => ['payment_intent.payment_method'],
]);

noble fractal
#

You need to do this instead:

$paymentIntent = \Stripe\PaymentIntent::create([
    'amount' => calculateOrderAmount($json_obj->items),
    'currency' => 'usd',
    'expand' => ['payment_method'],
  ]);
dry river
#

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

noble fractal
#

Is that the response from the creation request, or from confirmation?

dry river
#

from the comfirmation I think

noble fractal
#

Ah, that's the issue then - expansion is per-request, so you need to specify it for the confirmation request as well

dry river
#

Sorry I dont understand

noble fractal
#

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.

dry river
#

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)
})

noble fractal
#

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

dry river
#

<?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?

stark mica
#

Hello! I'm taking over for @noble fractal, let me get caught up. ๐Ÿ™‚

dry river
#

sure thank you

stark mica
#

Ah, okay, we need your JavaScript code, not your PHP code. The JavaScript from your website.

dry river
#

ok

stark mica
#

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']
    })
dry river
#

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?

stark mica
dry river
#

excellent thank you very much for your quick help, karbi and you, this is one of the best supports Ive ever seen.

#

thats all I needed help with, Thank you very much