简体   繁体   中英

iOS Stripe - Get card token without ephemeral key?

When implementing Stripe in Android there is CardInputWidget which gives you a Card object, then you get a token from Stripe API using that card and finally you send that token to your server, which makes the charge.

When implementing Stripe in iOS I can see that the workflow is quite different. The server needs to have an API endpoint to provide Stripe ephemeral key . Is there any way to do it like in Android workflow - without ephemeral key ?

let stripeCard = STPCardParams() /// Declare Stripe Payment Function
stripeCard.name = "Card Name" // you can enter Card Owner name which is displayed in card
stripeCard.number = "Card number" //You can enter card Number which is displayed in Card
stripeCard.expMonth = "ExpireMonth" // enter expire Month which is displayed in Card
stripeCard.expYear = "ExpireYear" // enter expire year which is displayed in Card
stripeCard.cvc = "CVV" // enter CVV which is displayed in Card
//after check card valid or not from below method
if STPCardValidator.validationState(forCard: self.stripeCard) == .valid 
{
// the card is valid.
print("Valid card")
STPAPIClient.shared().createToken(withCard: self.stripeCard, completion: { (token, error) -> Void in
    if error != nil {
    print(error ?? "")
    return
    }

    print(token!) 
    // call your php Api Pass token id which is given bellow link PHP API link
    APICallResponse.shared.getStripePayment(arrUserLoginDetails:          self.arrStripePayement,vc:self, completion: {data in
      self.SkripePayment = data 
    })
}
}

You can take reference of PHP API from given link

Stripe payment with php

Yes, absolutely, you can develop with Stripe's iOS SDK without using their pre-built UI or ephemeral key method.

You can use your own form or the STPPaymentCardTextField class, create a STPCardParams instance, and then create a STPToken from that which you can send off to your backend.

STPCardParams *cardParams = [[STPCardParams alloc] init];
cardParams.number = @"4242424242424242";
cardParams.expMonth = 10;
cardParams.expYear = 2020;
cardParams.cvc = @"345";

[[STPAPIClient sharedClient] createTokenWithCard:cardParams completion:^(STPToken *token, NSError *error) {
  ...
}
}];

See https://stripe.com/docs/mobile/ios/custom#stpapiclient--stpcardparams for more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM