#Umeed Emad - PaymentIntent

1 messages · Page 1 of 1 (latest)

remote matrix
#

Hi there!

#

How are you collecting payments? With PaymentIntent + PaymentElement?

whole flame
#

Hi

#

yes using strip-php and stripe js

#

<?php
require_once dirname(FILE)."/../lib/stripe-php-master/init.php";

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

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
    // people from directly manipulating the amount on the client
    return 1400;
}

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

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

    // Create a PaymentIntent with amount and currency
    $paymentIntent = \Stripe\PaymentIntent::create([
        'amount' => calculateOrderAmount($jsonObj->items),
        'currency' => 'usd',
        'automatic_payment_methods' => [
            'enabled' => false,
        ],
    ]);

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

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

?>

#

Do I need payment intent for one time donation too?

remote matrix
#

So you create a PaymentIntent on the backend, and then collect payment information with the PaymentElement?

#

If so, yes you first need to create a PaymentIntent to display the payment form.

whole flame
#

Is it possible to create payment intent when user clicks on submit? Can't I initiate card element without payment intent?

dire apex
#

Not the Payment Element, no

whole flame
#

what is the alternative solution? I only need a basic donation form which I can enable donors to pay for specific event. So the only thing I need to pass some meta data and make the payment and store the data in WordPress database.

dire apex
#

Have you considered using Payment Links?

whole flame
#

no. Actually I am quite new to stripe integration. I appreciate if you can guide please

dire apex
whole flame
#

Thank you.