chargebee / chargebee-checkout-samples

36 stars 69 forks source link

PHP Create payment intent - Need help #195

Open jcfgt opened 1 year ago

jcfgt commented 1 year ago

Hi

We use now the ChargeBee_HostedPage::checkoutNewForItems (PHP) to procees the payment.

But I have to change the integration, from a Wordpress page to a React SPA. I integrated your ReactJS component into.

If I correctly understood, I need to create an intent payment, to generate a token (server side), which will be used in the submit action (client side).

Actuelly I am a little lost.

Do those inputs/options/args can be used for an intent payment ?

[
        "subscription" => ["startDate" => now(),
         "subscriptionItems" => [
                       ["itemPriceId" => "my-item-price-id"]
          ],  
        "customer" => "John Doe",
        "couponIds" => ['my-coupon],
];

If it is not possible, how can I do ? Must have I create a subscription ?

Do you have an example in PHP ?

Thank you.

jcfgt commented 1 year ago

Hi there Maybe I didn't understand your examples.

With Card component, can I use HostedNewCheckout ?

jcfgt commented 1 year ago

@cb-dinesh Could you help me ?

Thank you :)

jcfgt commented 1 year ago

Hi, @cb-dinesh

There, what I did server side

            $startDate = new DateTime(date('Y-m-d'), new DateTimeZone('Europe/Paris'));
            $startDate->add(DateInterval::createFromDateString('14 day'));

            $paymentIntent = PaymentIntent::create([
                'amount' => $parameters['amount'],
                'currency_code' => $parameters['currencyCode'],
                'payment_method_type' => $parameters['paymentMethodType'],
            ]);

            $subscription = Subscription::create([
                "startDate" => $startDate->format('c'),
                "invoiceNotes" => "Formation : {$parameters['formation']} Durée: {$parameters['duration']} heures en FOAD.",
                "customer" => [
                    'firstName' => $parameters['firstName'],
                    'lastName' => $parameters['lastName'],
                    'locale' => "fr"
                ],
                "card" => ["gateway_account_id" => $paymentIntent["gateway_account_id"]],
                'subscriptionItems' => [
                    ['itemPriceId' => $parameters['itemPriceId']]
                ],
                'couponIds' => [$parameters['coupon']],
            ]);

            return json_encode($subscription);
cb-dinesh commented 1 year ago

Hi @jcfgt, can you please help me understand your usecase better. Are you planning to use Chargebee's hosted page or the collect card information directly in your web page?

Chargebee's hosted pages takes care of cart, collecting billing & shipping details, payments and creating a subscription / one time purchase.

Whereas, if you decide to use Chargebee's components & fields, you will be able to get a authorized payment intent, which can be used while calling Chargebee's create subscription, create invoice, or create payment method API from your server.

jcfgt commented 1 year ago

Hi @cb-dinesh

I am using the react component as front end integration.

Previously we used Chargebee's hosted pages in PHP pages. Now we need to use Chargebee's component in React pages and create ou payment method.

So, I want to know if I forget something, server side (cf my previous post with code)

If I correctly understood, I have to manage an intent payment and a subscription to be able to pass a coupon and other business information.

Could you help me, drive me, to implement it correctly? What I miss ? What I need ? What is the correct order to do it ?