capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
https://capacitor-community-stripe.netlify.app/
MIT License
196 stars 77 forks source link

The PaymentIntent object #202

Closed Th-Barth closed 2 years ago

Th-Barth commented 2 years ago

Hello, I m trying to get into your Stripe project but have problems with some inconsistencies.

When creating a payment intent the method Stripe.createPaymentSheet expects three variables (paymentIntent, ephemeralKey, customer):

    const { paymentIntent, ephemeralKey, customer } = await this.http.post<{
    paymentIntent: string;
    ephemeralKey: string;
    customer: string;
  }>(environment.api + 'intent', {}).pipe(first()).toPromise(Promise);

Compared to the expected response found at https://stripe.com/docs/api/payment_intents/object I can not find all appropriate variables.

"id": "pi_1JKS5a2Tb35ankTn5AFisSig", "object": "payment_intent", "customer": null, ????

<?php [...] \Stripe\Stripe::setApiKey('sktest...');

$intent = \Stripe\PaymentIntent::create([ 'amount' => 1099, 'currency' => 'eur', 'payment_method_types' => ['card'], ]);

echo json_encode(array('client_secret' => $intent->client_secret)); ?> ` Which object variables do I have to put into the array for json_encode?

rdlabo commented 2 years ago

@Th-Barth Hi, thanks for issue. Please check implements of server-demo: https://github.com/capacitor-community/stripe/blob/master/demo/server/src/app.controller.ts

This is written in Node, but the essential process is the same. Thanks.

Th-Barth commented 2 years ago

Hi,

thanks for responding. Here is my current php test version now:

use Stripe\Stripe;

try {
  \Stripe\Stripe::setApiKey('sk_test_51...');

  $customer = \Stripe\Customer::create();

  $ephemeralKey = \Stripe\EphemeralKey::create(
    ['customer' => $customer->id],
    ['stripe_version' => '2020-08-27']);

  $intent = \Stripe\PaymentIntent::create([
    'amount' => 100,
    'currency' => 'eur',
    'customer' => $customer->id,
    'automatic_payment_methods' => ['enabled' => 'true']
  ]);

  echo json_encode(['paymentIntent' => $intent->client_secret,
                    'ephemeralKey' => $ephemeralKey->secret,
                    'customer' => $customer->id]);

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

I got the final result "completed" after sending the sheet .

Today I had among other things a problem with the version transfer. I first always passed the version number of Stripe installed via composer on the server. But I had to pass the API version which is shown in the dashboard :-/ This caused an error in the server log: PHP Fatal error: Uncaught (Status 400) Invalid Stripe API version: 2022-07-25\n thrown in /var/www/.../vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

What also surprised me is that try/catch could not catch this error.

And there is another error or app crash, when you press the close button of the sheet after presentation. Is this normal for this demo version?

I ve got another question. Why do I get in this demo just a very simple payment sheet formular? With the settings

'automatic_payment_methods' => ['enabled' => 'true']

I expected all payment methods for my region like listed on this page https://stripe.com/docs/payments/payment-element

Have I perhaps forgotten or misunderstood something?

rdlabo commented 2 years ago

@Th-Barth This does not seem to be a question about this plugin. You should talk to the experts at stripe at https://github.com/stripe/stripe-php.

Best regards.

Th-Barth commented 2 years ago

You re right, sorry. In the meantime I got some help from Stripe und I was able to implement stripe-elements into my project.

rdlabo commented 2 years ago

@Th-Barth No worries. I'm glad you got it sorted out! Did you use this plugin for production? If yes, please tell us what app. This help development this plugin.

👉 https://github.com/capacitor-community/stripe/issues/145

Thanks.