stripe / stripe-dotnet

Stripe.net is a sync/async .NET 4.6.1+ client, and a portable class library for stripe.com.
Apache License 2.0
1.36k stars 572 forks source link

Forward the Apple Pay token to Stripe using Stripe.net #2694

Closed demonguru18 closed 1 year ago

demonguru18 commented 1 year ago

Is your feature request related to a problem? Please describe.

We have encountered a problem, after we successfully generate an Apple Pay token on our Mobile App for iOS using Ionic and Angular. We send the token to our backend written in Asp.Net to decrypt it using the Apple Decrypted Library. Using the Private Key and Provision Certificate, we are able to decrypt the token. We want to send this Decrypted to token to Stripe using Strip.net SDK. We cannot find any documentation to do so. When we contacted Stripe Support, we were told to communicate our request here on GitHub. If you can let us know if there is a way to forward the Token to Stripe or the steps to follow.

Support Contact image image

Decrypted Token on Mobile app image

Our Implementation image

Your help will be helpful as we need to implement this on 1000+ mobile apps build in Ionic and Angular. Currently our Merchants are using Stripe on their Websites and want to stick to Stripe on Mobile app as well for Payments.

Describe the solution you'd like

Something like this - Pass the token using Attach the decrypted Apple Pay token to the PaymentIntent object. You can use the following code to attach the token: image

Once the PaymentIntent object is created and the decrypted Apple Pay token is attached, you can confirm the PaymentIntent using the Stripe.net library. You can use the following code to confirm the PaymentIntent:

image

Describe alternatives you've considered

We cannot find stripe Alternative, some suggestions say we can achieve this with Braintree, but we want to stick to stripe.net

Additional context

This feature is very useful for us. Please do consider

remi-stripe commented 1 year ago

Hey @demonguru18 Thanks for the detailed report!

We cannot find any documentation to do so. When we contacted Stripe Support, we were told to communicate our request here on GitHub. I'm sorry to hear that. This is definitely an integration support question and something our support team should have helped you figure out or escalated to other people internally to get you a definitive answer.

Overall, we do not have any official support for this in our libraries today. It can work, and our API supports this, but it's extremely rare that someone needs to do this and we don't plan to add official support for it for now. We do highly recommend using our official iOS SDK instead to collect payment method details whether via Apple Pay or not and that's what I'd recommend you look into in the future.

Now, while we don't officially support this in client libraries, it does work and since you hit a wall with our support team, I don't want to just send you back there to try and get the answer. The process is a little bit convoluted but you basically need to do this in 2 steps:

First create a card Token with the decrypted information:

POST /v1/tokens
{
  pk_token: '<PKPaymentToken.paymentData decoded as JSON>',
  pk_token_instrument_name: '<PKPaymentToken.paymentInstrumentName>'
  pk_token_payment_network: '<PKPaymentToken.paymentNetwork>',
  pk_token_transaction_id: '<PKPaymentToken.transactionIdentifier>'
}

To do this with stripe-dotnet you have to use the AddExtraParam method documented here like this:

var options = new TokenCreateOptions();
options.AddExtraParam("pk_token", "xxx");
options.AddExtraParam("pk_token_instrument_name", "yyy");
options.AddExtraParam("pk_token_payment_network", "zzz");
options.AddExtraParam("pk_token_transaction_id", "123");
var service = new TokenService();
var token = service.Create(options);

After you get that Token id, you then need to create a PaymentMethod from it using the Payment Method create API like this:

var options = new PaymentMethodCreateOptions
{
  Type = "card",
  Card = new PaymentMethodCardOptions
  {
    Token = token.id,
  },
};
var service = new PaymentMethodService();
var paymentMethod = service.Create(options);

We do have other solutions a bit more advanced but they are in private beta right now and you need a custom setting on your account to access them. So while what I said above should work, I'd still recommend getting back to our support team and asking to be escalated to an engineering team that can help you further. Show them this thread and my comments (since I work for Stripe, they should be able to escalate you to the right place).

techFB commented 4 months ago

@remi-stripe hello! I'm actually encountering a similar issue / use case on my end. We have multiple payment processors and it's critical for us to send send a decrypted apple pay token to stripe. So far wasn't able to solve this with support and found this thread maybe you can help out.

When trying to pass decrypted token to "pk_token" parameter, I'm getting "Your payment information is formatted improperly" error. But it does seem to work when passing an encrypted paymentData from the token.

My question here is, is there a way to actually pass a decrypted token, with our own certificates to Stripe? This is how decrypted "paymentedData" JSON looked like in my pk_token request: { applicationPrimaryAccountNumber: 'XXX', applicationExpirationDate: 'XXX', currencyCode: 'XXX', transactionAmount: XX, deviceManufacturerIdentifier: 'XXXX', paymentDataType: '3DSecure', paymentData: { onlinePaymentCryptogram: 'XXXXX' } } Maybe there's a different format I can use?

I've also tried to pass primaryAccount number / expiration date as normal credit card info with /payment_intent API, but additionally providing three_d_secure data. But there I'm encountering an issue that apple transaction id is not accepted, because it's not an UUID.

@demonguru18 where you able to solve your issue, if so how?

Thank you all in advance!

remi-stripe commented 4 months ago

@demonguru18 the pk_token parameter is not really supported anymore. We do have a beta that allows you to get access to do what you want. Unfortunately, only our support team can help. Go back to support, share a link to this Github issue and mention that I told you there's a real beta you need access to. They should be able to route you to the right place to get access to this feature.

techFB commented 4 months ago

@remi-stripe thank you so much Remi! I'll try to do this with support 🤞

techFB commented 4 months ago

@remi-stripe just a quick question. Is there some kind of specific name that this "beta" has that I can mention to support person or just linking this issue will be enough?

remi-stripe commented 4 months ago

Our betas don't really have names but you can tell them to look for a beta related to wallets_decrypted_token_params which might help

techFB commented 4 months ago

@remi-stripe thank you for helping out earlier! I've contacted support just as you said, they're currently working on this case 🙏

I was also able to figure out a temporary (not ideal) solution. And that is to pass 3DS cryptogram from apple pay token via 3DS api from here. The only weird thing I had do to is to generate a random UUID for "transaction_id" there, because it seems to be incompatible with transaction_id from apple token. Approve rates seem to be fine for now. But probably won't recommend this outside of testing.

@remi-stripe I had one more question, maybe you know which direction to point me to. Let's say we have an internal database of apple pay DPANs and transaction_ids from our previous processor securely stored in accordance w/ PCI-DSS. Do you know if it's possible to perform an MIT (merchant initiated transaction) with stripe with this info? Maybe some additional verification is required from somewhere? (if we don't want to perform a general import and just do a specific MIT)

Thank you!

remi-stripe commented 4 months ago

@techFB I'd recommend talking to our support team for further help on those questions, I can't really answer this here sorry!

techFB commented 4 months ago

@remi-stripe Will do thanks!