What is a Stripe "STPCard" object?

1.2k views Asked by At

I was working through an iOS Stripe tutorial, and at one point, we need to create some kind of "STPCard" object to send to Stripe's server. What I'm wondering, is do we have to create the STPCard object ourselves, or is it already given to us in Stripe's framework?

If we do have to make it, could someone please provide some insight on how to go about doing it (ie: which properties it should have, etc). Any help would be greatly appreciated!

The tutorial gave the following block of code, but when I try to instantiate the STPCard, i'm getting a warning for unknown receiver.

- (IBAction)save:(id)sender {
  STPCard *card = [[STPCard alloc] init];
  card.number = self.paymentView.card.number;
  card.expMonth = self.paymentView.card.expMonth;
  card.expYear = self.paymentView.card.expYear;
  card.cvc = self.paymentView.card.cvc;
  [[STPAPIClient sharedClient] createTokenWithCard:card
      completion:^(STPToken *token, NSError *error) {
    if (error) {
      [self handleError:error];
    } else {
      [self createBackendChargeWithToken:token];
    }
  }];
}
3

There are 3 answers

0
Chandra Naveen On

As per stripe,you cannot create a STPCard object ,it is returned by the STPAPIClient callback.

0
ralph007 On

Stripe does want the credit card information collected from a user to be safe, so it treats the card info as an object, then return a token as result, which you will send to your backend so you can charge the card

0
onmyway133 On

You can receive STPCard from customer object, or manually construct STPCard and validate it

Take a look https://stripe.com/docs/api/cards/object?lang=node and validator https://stripe.dev/stripe-ios/docs/Classes/STPCardValidator.html

This class contains static methods to validate card numbers, expiration dates, and CVCs. For a list of test card numbers to use with this code, see https://stripe.com/docs/testing