Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The PaymentIntent object #202

Closed
Th-Barth opened this issue Jul 26, 2022 · 5 comments
Closed

The PaymentIntent object #202

Th-Barth opened this issue Jul 26, 2022 · 5 comments

Comments

@Th-Barth
Copy link

Th-Barth commented Jul 26, 2022

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('sk_test_...');

$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
Copy link
Member

rdlabo commented Jul 26, 2022

@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
Copy link
Author

Th-Barth commented Jul 27, 2022

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
Copy link
Member

rdlabo commented Aug 5, 2022

@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
Copy link
Author

Th-Barth commented Aug 5, 2022

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
Copy link
Member

rdlabo commented Aug 5, 2022

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

👉 #145

Thanks.

@rdlabo rdlabo closed this as completed Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants