#shibby-paymentintent-amount

1 messages · Page 1 of 1 (latest)

indigo sedgeBOT
olive mantle
#

shibby-paymentintent-amount

#

@echo widget it's tough to say without more details unfortunately. This is mostly something in your own code and unrelated to Stripe overall. We expect a total amount when you call the Create PaymentIntent API: https://stripe.com/docs/api/payment_intents/create

So in your code in PHP you need to figure out how to calculate the total amount associated with your cart (unrelated to Stripe) and then pass that amount/variable to our API

echo widget
#

thanks, I can show some of the code if that helps.
I have no issues calculating the total I'm pulling it from my database and storing it as a PHP variable which I can echo out.

#

<?php
require_once('../vendor/autoload.php');

// This is your test secret API key.
\Stripe\Stripe::setApiKey('sk_test_51KZmodifiedblablablaFvls');

header('Content-Type: application/json');

try {
// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
//print_r($jsonObj->total);

// Create a PaymentIntent with amount and currency
$paymentIntent = \Stripe\PaymentIntent::create([
    'amount' => 1234,
    'currency' => 'aud',
    'automatic_payment_methods' => [
        'enabled' => true,
    ],
]);

$output = [
    'clientSecret' => $paymentIntent->client_secret,
];

echo json_encode($output);

} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}

olive mantle
#

'amount' => 1234, -> this is what you need to change to map to what your total cart amount is

echo widget
#

I'm trying to get the value into the amount key of the payment intent
I tried putting the variable there but its just blank

olive mantle
#

I mean if it's blank it's likely just that the variable is null or empty really

echo widget
#

ill show the other page it may help

olive mantle
#

I don't really need another page

#

PHP doesn't have a concept of multiple page and memory and such. What you need is to make sure that this exact code you shared is where you retrieve the total cart amount

echo widget
#

ok im posting to this page from the other one

olive mantle
#

@echo widget you never shared any additional information