stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.11k stars 976 forks source link

Unable to get StripeId #1703

Closed tapannathvani closed 3 years ago

tapannathvani commented 3 years ago

Summary

Once Payment successful, i want to get the StripeId (normally i think we can say transaction id.. please correct here if i am wrong and that i need to sendback to server to store for further reference) but paymentContext.selectedPaymentOption not providing this. We are using your Basic Integration example directly.

Code to reproduce

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
    self.paymentInProgress = false
    let title: String
    let message: String
    switch status {
    case .error:
        title = "Error"
        message = error?.localizedDescription ?? ""
    case .success:
        title = "Success"
        message = "Your purchase was successful!"
    case .userCancellation:
        return()
    @unknown default:
        return()
    }
    print("PAYMENT STRIPE ID :", paymentContext.selectedPaymentOption.stripeId)

    let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
    let action = UIAlertAction(title: "OK", style: .default, handler: nil)
    alertController.addAction(action)
    self.present(alertController, animated: true, completion: nil)
}

iOS version

12.4

Installation method

Through POD

SDK version

github "AliSoftware/OHHTTPStubs" "8.0.0" github "capitalone/SWHttpTrafficRecorder" "1.0.2" github "erikdoe/ocmock" "v3.7.1" github "uber/ios-snapshot-test-case" "6.1.0"

Other information

Attached the screenshot. Screenshot 2020-10-29 at 11 10 57 AM

davidme-stripe commented 3 years ago

Hello! I'm not sure what you're using the stripeId for, but it looks like you need to cast the selectedPaymentOption: (paymentContext.selectedPaymentOption as STPPaymentMethod).stripeId. For this sort of question, you may have a faster response by using the Contact support button on https://support.stripe.com/.

tapannathvani commented 3 years ago

StripeId is one kind of TransactionId right? that we need to send it to our server for data records.

aliriaz-stripe commented 3 years ago

@tapannathvani the stripeId property is the Stripe object's ID.

e.g. in your case, you have a PaymentMethod object, so stripeId would be the PaymentMethod object ID, like pm_123. It is not a transaction ID, it is the ID of a token that represents a customer's card.

You still have to "confirm" a PaymentIntent to actually create the payment. You would use this PaymentMethod and a PaymentIntent's client_secret to confirm a payment as explained here: https://stripe.com/docs/payments/accept-a-payment?integration=elements#ios-create-payment-intent

I'm going to close this for now as this isn't about a bug in the SDK. For integration related questions, I'd recommend writing in to Support at https://support.stripe.com/contact and they can help you out!

tapannathvani commented 3 years ago

Hi, Thanks for the response. I am using the confirmPayment method with client_secret parameter and once payment successful then only i came into that didFinish delegate where i am getting stripeId. The link you have suggested that exactly i followed (even followed Basic Integration example also).

Here is the flow :

  1. create customer key and we get the response with customer id
  2. with that customer id we are calling create payment intent
  3. We received client_secret from create payment intent method and pass the same client_secret to confirmPayment method
  4. Once payment done then we received a call back in paymentcontent didFinish delegate and there are we have all the payment data like card detail, shipping details and stripe id.. So now what will be the process exactly to get the transactionId
tapannathvani commented 3 years ago

Hello Any update on above question

aliriaz-stripe commented 3 years ago

@tapannathvani in the completion block of confirmPayment(), you get back an STPPaymentIntent object as part of the completion block's parameters: https://stripe.dev/stripe-ios/docs/Classes/STPAPIClient.html#/c:objc(cs)STPAPIClient(im)confirmPaymentIntentWithParams:completion:

That STPPaymentIntent object has a stripeId which will be the PaymentIntent ID, e.g. pi_123. This PaymentIntent ID represents a payment.

tapannathvani commented 3 years ago

Okies. Thanks