├── .gitignore ├── src └── ios │ ├── Stripe.framework │ ├── Versions │ │ ├── Current │ │ └── A │ │ │ ├── Modules │ │ │ └── module.modulemap │ │ │ ├── Stripe │ │ │ └── Headers │ │ │ ├── STPCardBrand.h │ │ │ ├── Stripe.h │ │ │ ├── STPCardValidationState.h │ │ │ ├── STPAPIClient+ApplePay.h │ │ │ ├── STPBankAccount.h │ │ │ ├── STPToken.h │ │ │ ├── Stripe+ApplePay.h │ │ │ ├── StripeError.h │ │ │ ├── STPCheckoutOptions.h │ │ │ ├── STPCheckoutViewController.h │ │ │ ├── STPCardValidator.h │ │ │ ├── STPCard.h │ │ │ ├── STPPaymentCardTextField.h │ │ │ └── STPAPIClient.h │ ├── Headers │ ├── Modules │ └── Stripe │ ├── CDVApplePay.h │ └── CDVApplePay.m ├── www └── applepay.js ├── plugin.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Headers: -------------------------------------------------------------------------------- 1 | Versions/Current/Headers -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Modules: -------------------------------------------------------------------------------- 1 | Versions/Current/Modules -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Stripe: -------------------------------------------------------------------------------- 1 | Versions/Current/Stripe -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module Stripe { umbrella header "Stripe.h" export * module * { export * } } 2 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Stripe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwoThreeSevenPlatform/cordova-plugin-applepay/HEAD/src/ios/Stripe.framework/Versions/A/Stripe -------------------------------------------------------------------------------- /src/ios/CDVApplePay.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | 6 | @interface CDVApplePay : CDVPlugin 7 | < 8 | PKPaymentAuthorizationViewControllerDelegate 9 | > 10 | { 11 | NSString *merchantId; 12 | NSString *callbackId; 13 | } 14 | 15 | - (void)setMerchantId:(CDVInvokedUrlCommand*)command; 16 | - (void)getAllowsApplePay:(CDVInvokedUrlCommand*)command; 17 | - (void)getStripeToken:(CDVInvokedUrlCommand*)command; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCardBrand.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCardBrand.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 7/24/15. 6 | // Copyright (c) 2015 Stripe, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * The various card brands to which a payment card can belong. 13 | */ 14 | typedef NS_ENUM(NSInteger, STPCardBrand) { 15 | STPCardBrandVisa, 16 | STPCardBrandAmex, 17 | STPCardBrandMasterCard, 18 | STPCardBrandDiscover, 19 | STPCardBrandJCB, 20 | STPCardBrandDinersClub, 21 | STPCardBrandUnknown, 22 | }; 23 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/Stripe.h: -------------------------------------------------------------------------------- 1 | // 2 | // Stripe.h 3 | // Stripe 4 | // 5 | // Created by Saikat Chakrabarti on 10/30/12. 6 | // Copyright (c) 2012 Stripe. All rights reserved. 7 | // 8 | 9 | #import "STPAPIClient.h" 10 | #import "StripeError.h" 11 | #import "STPBankAccount.h" 12 | #import "STPCardBrand.h" 13 | #import "STPCard.h" 14 | #import "STPCardValidationState.h" 15 | #import "STPCardValidator.h" 16 | #import "STPToken.h" 17 | 18 | #import "STPCheckoutOptions.h" 19 | #import "STPCheckoutViewController.h" 20 | 21 | #if TARGET_OS_IPHONE 22 | #import "Stripe+ApplePay.h" 23 | #import "STPAPIClient+ApplePay.h" 24 | #import "STPPaymentCardTextField.h" 25 | #endif 26 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCardValidationState.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCardValidationState.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 8/7/15. 6 | // Copyright (c) 2015 Stripe, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * These fields indicate whether a card field represents a valid value, invalid value, or incomplete value. 13 | */ 14 | typedef NS_ENUM(NSInteger, STPCardValidationState) { 15 | STPCardValidationStateValid, // The field's contents are valid. For example, a valid, 16-digit card number. 16 | STPCardValidationStateInvalid, // The field's contents are invalid. For example, an expiration date of "13/42". 17 | STPCardValidationStateIncomplete, // The field's contents are not yet valid, but could be by typing additional characters. For example, a CVC of "1". 18 | }; 19 | -------------------------------------------------------------------------------- /www/applepay.js: -------------------------------------------------------------------------------- 1 | var ApplePay = { 2 | 3 | getAllowsApplePay: function(successCallback, errorCallback) { 4 | cordova.exec( 5 | successCallback, 6 | errorCallback, 7 | 'ApplePay', 8 | 'getAllowsApplePay', 9 | [] 10 | ); 11 | }, 12 | 13 | setMerchantId: function(successCallback, errorCallback, merchantId) { 14 | cordova.exec( 15 | successCallback, 16 | errorCallback, 17 | 'ApplePay', 18 | 'setMerchantId', 19 | [merchantId] 20 | ); 21 | }, 22 | 23 | getStripeToken: function(successCallback, errorCallback, amount, name, cur) { 24 | cordova.exec( 25 | successCallback, 26 | errorCallback, 27 | 'ApplePay', 28 | 'getStripeToken', 29 | [amount, name, cur] 30 | ); 31 | } 32 | 33 | }; 34 | 35 | module.exports = ApplePay; 36 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPAPIClient+ApplePay.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPAPIClient+ApplePay.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 12/19/14. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | #import "STPAPIClient.h" 12 | 13 | 14 | @interface STPAPIClient (ApplePay) 15 | 16 | /** 17 | * Converts a PKPayment object into a Stripe token using the Stripe API. 18 | * 19 | * @param payment The user's encrypted payment information as returned from a PKPaymentAuthorizationViewController. Cannot be nil. 20 | * @param completion The callback to run with the returned Stripe token (and any errors that may have occurred). 21 | */ 22 | - (void)createTokenWithPayment:(nonnull PKPayment *)payment completion:(nonnull STPCompletionBlock)completion; 23 | 24 | // Form-encodes a PKPayment object for POSTing to the Stripe API. This method is used internally by STPAPIClient; you should not use it in your own code. 25 | + (nonnull NSData *)formEncodedDataForPayment:(nonnull PKPayment *)payment; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | ApplePay 9 | Implements Stripe/ApplePay Stuff. 10 | cordova,payment,apple,pay,stripe 11 | git@github.com:fan-si/cordova-plugin-applepay.git 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | $STRIPE_PUBLISHABLE_KEY 38 | 39 | 40 | 41 | $APPLE_PAY_MERCHANT 42 | 43 | 44 | 45 | 46 | $APPLE_PAY_MERCHANT 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-applepay 2 | 3 | This plugin is a basic implementation of Stripe and Apple Pay with the purpose of returning a useable stripe token. 4 | 5 | 6 | ## Installation 7 | 8 | 1. Follow the steps on https://stripe.com/docs/mobile/apple-pay to get your certs generated 9 | 2. In your Xcode project, go to **Capabilities** and enable **Apple Pay** 10 | 3. Install the plugin 11 | ```sh 12 | cordova plugin add https://github.com/arzynik/cordova-plugin-applepay \ 13 | --variable STRIPE_PUBLISHABLE_KEY="pk_test_stripekey" \ 14 | --variable APPLE_PAY_MERCHANT="merchant.apple.test" 15 | ``` 16 | 17 | ## Supported Platforms 18 | 19 | - iOS 20 | 21 | ## Methods 22 | 23 | - ApplePay.getAllowsApplePay 24 | - ApplePay.setMerchantId 25 | - ApplePay.getStripeToken 26 | 27 | #### ApplePay.getAllowsApplePay 28 | 29 | Returns successfully if the device is setup for Apple Pay (correct software version, correct hardware & has card added). 30 | 31 | ```js 32 | ApplePay.getAllowsApplePay(successCallback, errorCallback); 33 | ``` 34 | 35 | #### ApplePay.setMerchantId 36 | 37 | Set your Apple-given merchant ID. This overrides the value obtained from **ApplePayMerchant** in **Info.plist**. 38 | 39 | ```js 40 | ApplePay.setMerchantId(successCallback, errorCallback, 'merchant.apple.test'); 41 | ``` 42 | 43 | #### ApplePay.getStripeToken 44 | 45 | Request a stripe token for an Apple Pay card. 46 | - amount (string) 47 | - description (string) 48 | - currency (uppercase string) 49 | 50 | ```js 51 | ApplePay.getStripeToken(successCallback, errorCallback, amount, description, currency); 52 | ``` 53 | 54 | ##### Response 55 | ```json 56 | { 57 | "token": "sometoken", 58 | "card": { 59 | "id": "cardid", 60 | "brand": "Visa", 61 | "last4": "1234", 62 | "exp_month": "01", 63 | "exp_year": "2050" 64 | } 65 | } 66 | ``` 67 | 68 | ## Example 69 | 70 | ```js 71 | ApplePay.setMerchantId('merchant.apple.test'); 72 | 73 | ApplePay.getAllowsApplePay(function() { 74 | 75 | ApplePay.getStripeToken(function(token) { 76 | alert('Your token is: ' + token.id); 77 | }, function() { 78 | alert('Error getting payment info'); 79 | }, '10.00', 'Delicious Cake', 'USD'); 80 | 81 | }, function() { 82 | alert('User does not have apple pay available'); 83 | }); 84 | 85 | ``` -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPBankAccount.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPBankAccount.h 3 | // Stripe 4 | // 5 | // Created by Charles Scalesse on 10/1/14. 6 | // 7 | // 8 | 9 | #import 10 | 11 | 12 | 13 | /** 14 | * Representation of a user's credit card details. You can assemble these with information that your user enters and 15 | * then create Stripe tokens with them using an STPAPIClient. @see https://stripe.com/docs/api#create_bank_account_token 16 | */ 17 | @interface STPBankAccount : NSObject 18 | 19 | /** 20 | * The account number for the bank account. Currently must be a checking account. 21 | */ 22 | @property (nonatomic, copy, nullable) NSString *accountNumber; 23 | 24 | /** 25 | * The routing number for the bank account. This should be the ACH routing number, not the wire routing number. 26 | */ 27 | @property (nonatomic, copy, nullable) NSString *routingNumber; 28 | 29 | /** 30 | * The country the bank account is in. 31 | */ 32 | @property (nonatomic, copy, nullable) NSString *country; 33 | 34 | /** 35 | * The default currency for the bank account. 36 | */ 37 | @property (nonatomic, copy, nullable) NSString *currency; 38 | 39 | #pragma mark - These fields are only present on objects returned from the Stripe API. 40 | /** 41 | * The Stripe ID for the bank account. 42 | */ 43 | @property (nonatomic, readonly, nullable) NSString *bankAccountId; 44 | 45 | /** 46 | * The last 4 digits of the account number. 47 | */ 48 | @property (nonatomic, readonly, nullable) NSString *last4; 49 | 50 | /** 51 | * The name of the bank that owns the account. 52 | */ 53 | @property (nonatomic, readonly, nullable) NSString *bankName; 54 | 55 | /** 56 | * A proxy for the account number, this uniquely identifies the account and can be used to compare equality of different bank accounts. 57 | */ 58 | @property (nonatomic, readonly, nullable) NSString *fingerprint; 59 | 60 | /** 61 | * Whether or not the bank account has been validated via microdeposits or other means. 62 | */ 63 | @property (nonatomic, readonly) BOOL validated; 64 | 65 | /** 66 | * Whether or not the bank account is currently disabled. 67 | */ 68 | @property (nonatomic, readonly) BOOL disabled; 69 | 70 | @end 71 | 72 | 73 | // This method is used internally by Stripe to deserialize API responses and exposed here for convenience and testing purposes only. You should not use it in your own code. 74 | @interface STPBankAccount (PrivateMethods) 75 | 76 | - (nonnull instancetype)initWithAttributeDictionary:(nonnull NSDictionary *)attributeDictionary; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPToken.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPToken.h 3 | // Stripe 4 | // 5 | // Created by Saikat Chakrabarti on 11/5/12. 6 | // 7 | // 8 | 9 | #import 10 | 11 | 12 | @class STPCard; 13 | @class STPBankAccount; 14 | 15 | /** 16 | * A token returned from submitting payment details to the Stripe API. You should not have to instantiate one of these directly. 17 | */ 18 | @interface STPToken : NSObject 19 | 20 | /** 21 | * You cannot directly instantiate an STPToken. You should only use one that has been returned from an STPAPIClient callback. 22 | */ 23 | - (nonnull instancetype) init __attribute__((unavailable("You cannot directly instantiate an STPToken. You should only use one that has been returned from an STPAPIClient callback."))); 24 | 25 | /** 26 | * The value of the token. You can store this value on your server and use it to make charges and customers. @see 27 | * https://stripe.com/docs/mobile/ios#sending-tokens 28 | */ 29 | @property (nonatomic, readonly, nonnull) NSString *tokenId; 30 | 31 | /** 32 | * Whether or not this token was created in livemode. Will be YES if you used your Live Publishable Key, and NO if you used your Test Publishable Key. 33 | */ 34 | @property (nonatomic, readonly) BOOL livemode; 35 | 36 | /** 37 | * The credit card details that were used to create the token. Will only be set if the token was created via a credit card or Apple Pay, otherwise it will be 38 | * nil. 39 | */ 40 | @property (nonatomic, readonly, nullable) STPCard *card; 41 | 42 | /** 43 | * The bank account details that were used to create the token. Will only be set if the token was created with a bank account, otherwise it will be nil. 44 | */ 45 | @property (nonatomic, readonly, nullable) STPBankAccount *bankAccount; 46 | 47 | /** 48 | * When the token was created. 49 | */ 50 | @property (nonatomic, readonly, nullable) NSDate *created; 51 | 52 | typedef void (^STPCardServerResponseCallback)(NSURLResponse * __nullable response, NSData * __nullable data, NSError * __nullable error); 53 | 54 | /** 55 | * Form-encode the token and post those parameters to your backend URL. 56 | * 57 | * @param url the URL to upload the token details to 58 | * @param params optional parameters to additionally include in the POST body 59 | * @param handler code to execute with your server's response 60 | * @deprecated you should write your own networking code to talk to your server. 61 | */ 62 | - (void)postToURL:(nonnull NSURL *)url withParams:(nullable NSDictionary *)params completion:(nullable STPCardServerResponseCallback)handler __attribute((deprecated)); 63 | 64 | @end 65 | 66 | // This method is used internally by Stripe to deserialize API responses and exposed here for convenience and testing purposes only. You should not use it in 67 | // your own code. 68 | @interface STPToken (PrivateMethods) 69 | 70 | - (nonnull instancetype)initWithAttributeDictionary:(nonnull NSDictionary *)attributeDictionary; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/Stripe+ApplePay.h: -------------------------------------------------------------------------------- 1 | // 2 | // Stripe+ApplePay.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 9/17/14. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | #import "Stripe.h" 12 | #import "STPAPIClient+ApplePay.h" 13 | 14 | 15 | @class Stripe; 16 | 17 | @interface Stripe (ApplePay) 18 | 19 | /** 20 | * Whether or not this device is capable of using Apple Pay. This checks both whether the user is running an iPhone 6/6+ or later, iPad Air 2 or later, or iPad 21 | *mini 3 or later, as well as whether or not they have stored any cards in Apple Pay on their device. 22 | * 23 | * @param paymentRequest The return value of this method depends on the supportedNetworks property of this payment request, which by default should be 24 | *@[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]. 25 | * 26 | * @return whether or not the user is currently able to pay with Apple Pay. 27 | */ 28 | + (BOOL)canSubmitPaymentRequest:(nullable PKPaymentRequest *)paymentRequest; 29 | 30 | /** 31 | * A convenience method to return a PKPaymentRequest with sane default values. You will still need to configure the paymentSummaryItems property to indicate 32 | *what the user is purchasing, as well as the optional requiredShippingAddressFields, requiredBillingAddressFields, and shippingMethods properties to indicate 33 | *what contact information your application requires. 34 | * 35 | * @param merchantIdentifier Your Apple Merchant ID, as obtained at https://developer.apple.com/account/ios/identifiers/merchant/merchantCreate.action 36 | * 37 | * @return a PKPaymentRequest with proper default values. Returns nil if running on < iOS8. 38 | */ 39 | + (nullable PKPaymentRequest *)paymentRequestWithMerchantIdentifier:(nonnull NSString *)merchantIdentifier; 40 | 41 | #pragma mark - deprecated methods 42 | 43 | /** 44 | * Securely convert your user's Apple Pay payment information into a Stripe token, which you can then safely store on your server and use to charge the user. 45 | * The URL connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 46 | * 47 | * @param payment The PKPayment instance to convert, as returned from a PKPaymentAuthorizationViewController 48 | * @param handler Code to run when the token has been returned (along with any errors encountered). 49 | * @deprecated use [[STPAPIClient sharedClient] createTokenWithPayment:completion:] instead. 50 | */ 51 | + (void)createTokenWithPayment:(nonnull PKPayment *)payment completion:(nonnull STPCompletionBlock)handler __attribute__((deprecated)); 52 | 53 | /** 54 | * Securely convert your user's Apple Pay payment information into a Stripe token, which you can then safely store on your server and use to charge the user. 55 | * The URL connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 56 | * 57 | * @param payment The PKPayment instance to convert, as returned from a PKPaymentAuthorizationViewController 58 | * @param queue The operation queue on which to run the URL connection. @see NSURLConnection 59 | * @param handler Code to run when the token has been returned (along with any errors encountered). 60 | * @deprecated use [[STPAPIClient sharedClient] createTokenWithPayment:completion:] instead. 61 | */ 62 | + (void)createTokenWithPayment:(nonnull PKPayment *)payment operationQueue:(nonnull NSOperationQueue *)queue completion:(nonnull STPCompletionBlock)handler __attribute__((deprecated)); 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/StripeError.h: -------------------------------------------------------------------------------- 1 | // 2 | // StripeError.h 3 | // Stripe 4 | // 5 | // Created by Saikat Chakrabarti on 11/4/12. 6 | // 7 | // 8 | 9 | #import 10 | 11 | 12 | 13 | /** 14 | * All Stripe iOS errors will be under this domain. 15 | */ 16 | FOUNDATION_EXPORT NSString * __nonnull const StripeDomain; 17 | 18 | typedef NS_ENUM(NSInteger, STPErrorCode) { 19 | STPConnectionError = 40, // Trouble connecting to Stripe. 20 | STPInvalidRequestError = 50, // Your request had invalid parameters. 21 | STPAPIError = 60, // General-purpose API error (should be rare). 22 | STPCardError = 70, // Something was wrong with the given card (most common). 23 | STPCheckoutError = 80, // Stripe Checkout encountered an error. 24 | }; 25 | 26 | #pragma mark userInfo keys 27 | 28 | // A developer-friendly error message that explains what went wrong. You probably 29 | // shouldn't show this to your users, but might want to use it yourself. 30 | FOUNDATION_EXPORT NSString * __nonnull const STPErrorMessageKey; 31 | 32 | // What went wrong with your STPCard (e.g., STPInvalidCVC. See below for full list). 33 | FOUNDATION_EXPORT NSString * __nonnull const STPCardErrorCodeKey; 34 | 35 | // Which parameter on the STPCard had an error (e.g., "cvc"). Useful for marking up the 36 | // right UI element. 37 | FOUNDATION_EXPORT NSString * __nonnull const STPErrorParameterKey; 38 | 39 | #pragma mark STPCardErrorCodeKeys 40 | 41 | // (Usually determined locally:) 42 | FOUNDATION_EXPORT NSString * __nonnull const STPInvalidNumber; 43 | FOUNDATION_EXPORT NSString * __nonnull const STPInvalidExpMonth; 44 | FOUNDATION_EXPORT NSString * __nonnull const STPInvalidExpYear; 45 | FOUNDATION_EXPORT NSString * __nonnull const STPInvalidCVC; 46 | 47 | // (Usually sent from the server:) 48 | FOUNDATION_EXPORT NSString * __nonnull const STPIncorrectNumber; 49 | FOUNDATION_EXPORT NSString * __nonnull const STPExpiredCard; 50 | FOUNDATION_EXPORT NSString * __nonnull const STPCardDeclined; 51 | FOUNDATION_EXPORT NSString * __nonnull const STPProcessingError; 52 | FOUNDATION_EXPORT NSString * __nonnull const STPIncorrectCVC; 53 | 54 | #pragma mark Strings 55 | 56 | #define STPCardErrorInvalidNumberUserMessage NSLocalizedString(@"Your card's number is invalid", @"Error when the card number is not valid") 57 | #define STPCardErrorInvalidCVCUserMessage NSLocalizedString(@"Your card's security code is invalid", @"Error when the card's CVC is not valid") 58 | #define STPCardErrorInvalidExpMonthUserMessage \ 59 | NSLocalizedString(@"Your card's expiration month is invalid", @"Error when the card's expiration month is not valid") 60 | #define STPCardErrorInvalidExpYearUserMessage \ 61 | NSLocalizedString(@"Your card's expiration year is invalid", @"Error when the card's expiration year is not valid") 62 | #define STPCardErrorExpiredCardUserMessage NSLocalizedString(@"Your card has expired", @"Error when the card has already expired") 63 | #define STPCardErrorDeclinedUserMessage NSLocalizedString(@"Your card was declined", @"Error when the card was declined by the credit card networks") 64 | #define STPUnexpectedError \ 65 | NSLocalizedString(@"There was an unexpected error -- try again in a few seconds", @"Unexpected error, such as a 500 from Stripe or a JSON parse error") 66 | #define STPCardErrorProcessingErrorUserMessage \ 67 | NSLocalizedString(@"There was an error processing your card -- try again in a few seconds", @"Error when there is a problem processing the credit card") 68 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCheckoutOptions.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCheckoutOptions.h 3 | // StripeExample 4 | // 5 | // Created by Jack Flintermann on 10/6/14. 6 | // 7 | 8 | #import 9 | 10 | #if TARGET_OS_IPHONE 11 | #import 12 | #define STP_IMAGE_CLASS UIImage 13 | #else 14 | #import 15 | #define STP_IMAGE_CLASS NSImage 16 | #endif 17 | 18 | 19 | 20 | /** 21 | * This class represents a configurable set of options that you can pass to an STPCheckoutViewController to control the appearance of 22 | * Stripe Checkout. For more information on how these properties behave, see https://stripe.com/docs/checkout#integration-custom 23 | */ 24 | @interface STPCheckoutOptions : NSObject; 25 | 26 | -(nonnull instancetype)initWithPublishableKey:(nonnull NSString *)publishableKey; 27 | 28 | #pragma mark - Required options 29 | 30 | /** 31 | * The Stripe publishable key to use for your Checkout requests. Defaults to [Stripe defaultPublishableKey]. Required. 32 | */ 33 | @property (nonatomic, copy, nonnull) NSString *publishableKey; 34 | 35 | #pragma mark - Strongly recommended options 36 | 37 | /** 38 | * This can be an external image URL that will load in the header of Stripe Checkout. This takes precedent over the logoImage property. The recommended minimum 39 | * size for this image is 128x128px. 40 | */ 41 | @property (nonatomic, copy, nullable) NSURL *logoURL; 42 | 43 | /** 44 | * You can also specify a local UIImage to be used as the Checkout logo header (see logoURL). 45 | */ 46 | @property (nonatomic, nullable) STP_IMAGE_CLASS *logoImage; 47 | 48 | /** 49 | * This specifies the color of the header shown in Stripe Checkout. If you specify a logoURL (but not a logoImage) and leave this property nil, Checkout will 50 | * auto-detect the background color of the image you point to and use that as the header color. 51 | */ 52 | #if TARGET_OS_IPHONE 53 | @property (nonatomic, copy, nullable) UIColor *logoColor; 54 | #else 55 | @property (nonatomic, copy, nullable) NSColor *logoColor; 56 | #endif 57 | 58 | /** 59 | * The name of your company or website. Displayed in the header. Defaults to your app's name. 60 | */ 61 | @property (nonatomic, copy, nullable) NSString *companyName; 62 | 63 | /** 64 | * A description of the product or service being purchased. Appears in the header. 65 | */ 66 | @property (nonatomic, copy, nullable) NSString *purchaseDescription; 67 | 68 | /** 69 | * The amount (in cents) that's shown to the user. Note that this is for display purposes only; you will still have to explicitly specify the amount when you 70 | * create a charge using the Stripe API. 71 | * @warning don't forget this is in cents! So for a $10 charge, specify 1000 here. 72 | */ 73 | @property (nonatomic) NSUInteger purchaseAmount; 74 | 75 | /** 76 | * If you already know the email address of your user, you can provide it to Checkout to be pre-filled. 77 | */ 78 | @property (nonatomic, copy, nullable) NSString *customerEmail; 79 | 80 | #pragma mark - Additional options 81 | 82 | /** 83 | * The label of the payment button in the Checkout form (e.g. “Subscribe”, “Pay {{amount}}”, etc.). If you include {{amount}}, it will be replaced by the 84 | * provided amount. Otherwise, the amount will be appended to the end of your label. Defaults to "Pay {{amount}}". 85 | */ 86 | @property (nonatomic, copy, nullable) NSString *purchaseLabel; 87 | 88 | /** 89 | * The currency of the amount (3-letter ISO code). The default is "USD". 90 | */ 91 | @property (nonatomic, copy, nonnull) NSString *purchaseCurrency; 92 | 93 | /** 94 | * Specify whether to include the option to "Remember Me" for future purchases (true or false). The default is true. 95 | */ 96 | @property (nonatomic, copy, nullable) NSNumber *enableRememberMe; 97 | 98 | /** 99 | * Specify whether Checkout should validate your user's billing ZIP code (true or false). The default is false. 100 | */ 101 | @property (nonatomic, copy, nullable) NSNumber *enablePostalCode; 102 | 103 | /** 104 | * Specify whether Checkout should require the user to enter their billing address. The default is false. 105 | */ 106 | @property (nonatomic, copy, nullable) NSNumber *requireBillingAddress; 107 | 108 | /** 109 | * Used internally by Stripe Checkout. 110 | * 111 | * @return a JSON string representing the options. 112 | */ 113 | - (nonnull NSString *)stringifiedJSONRepresentation; 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCheckoutViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCheckoutViewController.h 3 | // StripeExample 4 | // 5 | // Created by Jack Flintermann on 9/15/14. 6 | // 7 | 8 | #import 9 | 10 | #if TARGET_OS_IPHONE 11 | #import 12 | #else 13 | #import 14 | #endif 15 | 16 | 17 | 18 | typedef NS_ENUM(NSInteger, STPPaymentStatus) { 19 | STPPaymentStatusSuccess, // The transaction was a success. 20 | STPPaymentStatusError, // The transaction failed. 21 | STPPaymentStatusUserCancelled, // The user Cancelled the payment sheet. 22 | }; 23 | 24 | @class STPCheckoutOptions, STPToken; 25 | @protocol STPCheckoutViewControllerDelegate; 26 | 27 | /** 28 | Controls a UIWebView that loads an iOS-optimized version of Stripe Checkout that you can present modally. Note that this functionality is considered in beta 29 | and may change. 30 | @deprecated this functionality is now deprecated. You should build your own UI to collect your user's credit card details. 31 | */ 32 | #if TARGET_OS_IPHONE 33 | __attribute__((deprecated("We've deprecated Checkout for iOS. You should build your own credit card form. See also: https://github.com/stripe/PaymentKit"))) 34 | @interface STPCheckoutViewController : UINavigationController 35 | #else 36 | __attribute__((deprecated("We've deprecated Checkout for OSX. You should build your own credit card form."))) 37 | @interface STPCheckoutViewController : NSViewController 38 | #endif 39 | 40 | /** 41 | * Creates an STPCheckoutViewController with the desired options. The options are copied at this step, so changing any of their values after instantiating an 42 | *STPCheckoutViewController will have no effect. 43 | * 44 | * @param options A configuration object that describes how to display Stripe Checkout. 45 | * 46 | */ 47 | - (nonnull instancetype)initWithOptions:(nonnull STPCheckoutOptions *)options NS_DESIGNATED_INITIALIZER; 48 | @property (nonatomic, readonly, copy, nonnull) STPCheckoutOptions *options; 49 | /** 50 | * Note: you must set a delegate before showing an STPViewController. 51 | */ 52 | @property (nonatomic, weak, nullable) id checkoutDelegate; 53 | 54 | @end 55 | 56 | @protocol STPCheckoutViewControllerDelegate 57 | 58 | /** 59 | * Called when the checkout view controller has finished displaying the "success" or "error" animation. At this point, the controller is done with its work. 60 | * You should dismiss the view controller at this point, probably by calling `dismissViewControllerAnimated:completion:`. 61 | * 62 | * @param controller the checkout view controller that has finished. 63 | * @param status the result of the payment (success, failure, or cancelled by the user). You should use this to determine whether to proceed to the success 64 | *state, for example. 65 | * @param error the returned error, if it exists. Can be nil. 66 | */ 67 | #pragma clang diagnostic push 68 | #pragma clang diagnostic ignored "-Wdeprecated" 69 | - (void)checkoutController:(nonnull STPCheckoutViewController *)controller didFinishWithStatus:(STPPaymentStatus)status error:(nullable NSError *)error; 70 | #pragma clang diagnostic pop 71 | 72 | /** 73 | * Use these options to inform Stripe Checkout of the success or failure of your backend charge. 74 | */ 75 | typedef NS_ENUM(NSInteger, STPBackendChargeResult) { 76 | STPBackendChargeResultSuccess, // Passing this value will display a "success" animation in the payment button. 77 | STPBackendChargeResultFailure, // Passing this value will display an "error" animation in the payment button. 78 | }; 79 | 80 | typedef void (^STPTokenSubmissionHandler)(STPBackendChargeResult status, NSError * __nullable error); 81 | 82 | /** 83 | * After the user has provided valid credit card information and pressed the "pay" button, Checkout will communicate with Stripe and obtain a tokenized version 84 | of their credit card. 85 | 86 | At this point, you should submit this token to your backend, which should use this token to create a charge. For more information on this, see 87 | // The delegate must call completion with an appropriate authorization status, as may be determined 88 | // by submitting the payment credential to a processing gateway for payment authorization. 89 | * 90 | * @param controller the checkout controller being presented 91 | * @param token a Stripe token 92 | * @param completion call this function with STPBackendChargeResultSuccess/Failure when you're done charging your user 93 | */ 94 | #pragma clang diagnostic push 95 | #pragma clang diagnostic ignored "-Wdeprecated" 96 | - (void)checkoutController:(nonnull STPCheckoutViewController *)controller 97 | didCreateToken:(nonnull STPToken *)token 98 | completion:(nonnull STPTokenSubmissionHandler)completion; 99 | #pragma clang diagnostic pop 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCardValidator.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCardValidator.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 7/15/15. 6 | // Copyright (c) 2015 Stripe, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "STPCardBrand.h" 12 | #import "STPCardValidationState.h" 13 | 14 | /** 15 | * 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 16 | */ 17 | @interface STPCardValidator : NSObject 18 | 19 | /** 20 | * Returns a copy of the passed string with all non-numeric characters removed. 21 | */ 22 | + (nonnull NSString *)sanitizedNumericStringForString:(nonnull NSString *)string; 23 | 24 | /** 25 | * Validates a card number, passed as a string. This will return STPCardValidationStateInvalid for numbers that are too short or long, contain invalid characters, do not pass Luhn validation, or (optionally) do not match a number format issued by a major card brand. 26 | * 27 | * @param cardNumber The card number to validate. Ex. @"4242424242424242" 28 | * @param validatingCardBrand Whether or not to enforce that the number appears to be issued by a major card brand (or could be). For example, no issuing card network currently issues card numbers beginning with the digit 9; if an otherwise correct-length and luhn-valid card number beginning with 9 (example: 9999999999999995) were passed to this method, it would return STPCardValidationStateInvalid if this parameter were YES and STPCardValidationStateValid if this parameter were NO. If unsure, you should use YES for this value. 29 | * 30 | * @return STPCardValidationStateValid if the number is valid, STPCardValidationStateInvalid if the number is invalid, or STPCardValidationStateIncomplete if the number is a substring of a valid card (e.g. @"4242"). 31 | */ 32 | + (STPCardValidationState)validationStateForNumber:(nonnull NSString *)cardNumber validatingCardBrand:(BOOL)validatingCardBrand; 33 | 34 | /** 35 | * The card brand for a card number or substring thereof. 36 | * 37 | * @param cardNumber A card number, or partial card number. For example, @"4242", @"5555555555554444", or @"123". 38 | * 39 | * @return The brand for that card number. The example parameters would return STPCardBrandVisa, STPCardBrandMasterCard, and STPCardBrandUnknown, respectively. 40 | */ 41 | + (STPCardBrand)brandForNumber:(nonnull NSString *)cardNumber; 42 | 43 | /** 44 | * The number length for cards associated with a card brand. For example, Visa card numbers contain 16 characters, while American Express cards contain 15 characters. 45 | */ 46 | + (NSInteger)lengthForCardBrand:(STPCardBrand)brand; 47 | 48 | /** 49 | * The length of the final grouping of digits to use when formatting a card number for display. For example, Visa cards display their final 4 numbers, e.g. "4242", while American Express cards display their final 5 digits, e.g. "10005". 50 | */ 51 | + (NSInteger)fragmentLengthForCardBrand:(STPCardBrand)brand; 52 | 53 | /** 54 | * Validates an expiration month, passed as an (optionally 0-padded) string. Example valid values are "3", "12", and "08". Example invalid values are "99", "a", and "00". Incomplete values include "0" and "1". 55 | * 56 | * @param expirationMonth A string representing a 2-digit expiration month for a payment card. 57 | * 58 | * @return STPCardValidationStateValid if the month is valid, STPCardValidationStateInvalid if the month is invalid, or STPCardValidationStateIncomplete if the month is a substring of a valid month (e.g. @"0" or @"1"). 59 | */ 60 | + (STPCardValidationState)validationStateForExpirationMonth:(nonnull NSString *)expirationMonth; 61 | 62 | /** 63 | * Validates an expiration year, passed as a string representing the final 2 digits of the year. This considers the period between the current year until 2099 as valid times. An example valid value would be "16" (assuming the current year, as determined by [NSDate date], is 2015). Will return STPCardValidationStateInvalid for a month/year combination that is earlier than the current date (i.e. @"15" and @"04" in October 2015. Example invalid values are "00", "a", and "13". Any 1-digit string will return STPCardValidationStateIncomplete. 64 | * 65 | * @param expirationYear A string representing a 2-digit expiration year for a payment card. 66 | * @param expirationMonth A string representing a 2-digit expiration month for a payment card. See -validationStateForExpirationMonth for the desired formatting of this string. 67 | * 68 | * @return STPCardValidationStateValid if the year is valid, STPCardValidationStateInvalid if the year is invalid, or STPCardValidationStateIncomplete if the year is a substring of a valid year (e.g. @"1" or @"2"). 69 | */ 70 | + (STPCardValidationState)validationStateForExpirationYear:(nonnull NSString *)expirationYear inMonth:(nonnull NSString *)expirationMonth; 71 | 72 | /** 73 | * The max CVC length for a card brand (for context, American Express CVCs are 4 digits, while all others are 3). 74 | */ 75 | + (NSUInteger)maxCVCLengthForCardBrand:(STPCardBrand)brand; 76 | 77 | /** 78 | * Validates a card's CVC, passed as a numeric string, for the given card brand. 79 | * 80 | * @param cvc the CVC to validate 81 | * @param brand the card brand (can be determined from the card's number using +brandForNumber) 82 | * 83 | * @return Whether the CVC represents a valid CVC for that card brand. For example, would return STPCardValidationStateValid for @"123" and STPCardBrandVisa, STPCardValidationStateValid for @"1234" and STPCardBrandAmericanExpress, STPCardValidationStateIncomplete for @"123" and STPCardBrandAmericanExpress, and STPCardValidationStateInvalid for @"12345" and any brand. 84 | */ 85 | + (STPCardValidationState)validationStateForCVC:(nonnull NSString *)cvc cardBrand:(STPCardBrand)brand; 86 | 87 | // Exposed for testing only. 88 | + (STPCardValidationState)validationStateForExpirationYear:(nonnull NSString *)expirationYear inMonth:(nonnull NSString *)expirationMonth inCurrentYear:(NSInteger)currentYear currentMonth:(NSInteger)currentMonth; 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPCard.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPCard.h 3 | // Stripe 4 | // 5 | // Created by Saikat Chakrabarti on 11/2/12. 6 | // 7 | // 8 | 9 | #import 10 | #import "STPCardBrand.h" 11 | 12 | /** 13 | * The various funding sources for a payment card. 14 | */ 15 | typedef NS_ENUM(NSInteger, STPCardFundingType) { 16 | STPCardFundingTypeDebit, 17 | STPCardFundingTypeCredit, 18 | STPCardFundingTypePrepaid, 19 | STPCardFundingTypeOther, 20 | }; 21 | 22 | /** 23 | * Representation of a user's credit card details. You can assemble these with information that your user enters and 24 | * then create Stripe tokens with them using an STPAPIClient. @see https://stripe.com/docs/api#cards 25 | */ 26 | @interface STPCard : NSObject 27 | 28 | /** 29 | * The card's number. This will be nil for cards retrieved from the Stripe API. 30 | */ 31 | @property (nonatomic, copy, nullable) NSString *number; 32 | 33 | /** 34 | * The last 4 digits of the card. Unlike number, this will be present on cards retrieved from the Stripe API. 35 | */ 36 | @property (nonatomic, readonly, nullable) NSString *last4; 37 | 38 | /** 39 | * For cards made with Apple Pay, this refers to the last 4 digits of the "Device Account Number" for the tokenized card. For regular cards, it will be nil. 40 | */ 41 | @property (nonatomic, readonly, nullable) NSString *dynamicLast4; 42 | 43 | /** 44 | * The card's expiration month. 45 | */ 46 | @property (nonatomic) NSUInteger expMonth; 47 | 48 | /** 49 | * The card's expiration year. 50 | */ 51 | @property (nonatomic) NSUInteger expYear; 52 | 53 | /** 54 | * The card's security code, found on the back. This will be nil for cards retrieved from the Stripe API. 55 | */ 56 | @property (nonatomic, copy, nullable) NSString *cvc; 57 | 58 | /** 59 | * The cardholder's name. 60 | */ 61 | @property (nonatomic, copy, nullable) NSString *name; 62 | 63 | /** 64 | * The cardholder's address. 65 | */ 66 | @property (nonatomic, copy, nullable) NSString *addressLine1; 67 | @property (nonatomic, copy, nullable) NSString *addressLine2; 68 | @property (nonatomic, copy, nullable) NSString *addressCity; 69 | @property (nonatomic, copy, nullable) NSString *addressState; 70 | @property (nonatomic, copy, nullable) NSString *addressZip; 71 | @property (nonatomic, copy, nullable) NSString *addressCountry; 72 | 73 | /** 74 | * The Stripe ID for the card. 75 | */ 76 | @property (nonatomic, readonly, nullable) NSString *cardId; 77 | 78 | /** 79 | * The issuer of the card. 80 | */ 81 | @property (nonatomic, readonly) STPCardBrand brand; 82 | 83 | /** 84 | * The issuer of the card. 85 | * Can be one of "Visa", "American Express", "MasterCard", "Discover", "JCB", "Diners Club", or "Unknown" 86 | * @deprecated use "brand" instead. 87 | */ 88 | @property (nonatomic, readonly, nonnull) NSString *type __attribute__((deprecated)); 89 | 90 | /** 91 | * The funding source for the card (credit, debit, prepaid, or other) 92 | */ 93 | @property (nonatomic, readonly) STPCardFundingType funding; 94 | 95 | /** 96 | * A proxy for the card's number, this uniquely identifies the credit card and can be used to compare different cards. 97 | * @deprecated This field will no longer be present in responses when using your publishable key. If you want to access the value of this field, you can look it up on your backend using your secret key. 98 | */ 99 | @property (nonatomic, readonly, nullable) NSString *fingerprint __attribute__((deprecated("This field will no longer be present in responses when using your publishable key. If you want to access the value of this field, you can look it up on your backend using your secret key."))); 100 | 101 | /** 102 | * Two-letter ISO code representing the issuing country of the card. 103 | */ 104 | @property (nonatomic, readonly, nullable) NSString *country; 105 | 106 | /** 107 | * This is only applicable when tokenizing debit cards to issue payouts to managed accounts. You should not set it otherwise. The card can then be used as a transfer destination for funds in this currency. 108 | */ 109 | @property (nonatomic, copy, nullable) NSString *currency; 110 | 111 | /** 112 | * Validate each field of the card. 113 | * @return whether or not that field is valid. 114 | * @deprecated use STPCardValidator instead. 115 | */ 116 | - (BOOL)validateNumber:(__nullable id * __nullable )ioValue 117 | error:(NSError * __nullable * __nullable )outError __attribute__((deprecated("Use STPCardValidator instead."))); 118 | - (BOOL)validateCvc:(__nullable id * __nullable )ioValue 119 | error:(NSError * __nullable * __nullable )outError __attribute__((deprecated("Use STPCardValidator instead."))); 120 | - (BOOL)validateExpMonth:(__nullable id * __nullable )ioValue 121 | error:(NSError * __nullable * __nullable )outError __attribute__((deprecated("Use STPCardValidator instead."))); 122 | - (BOOL)validateExpYear:(__nullable id * __nullable)ioValue 123 | error:(NSError * __nullable * __nullable )outError __attribute__((deprecated("Use STPCardValidator instead."))); 124 | 125 | /** 126 | * This validates a fully populated card to check for all errors, including ones that come about 127 | * from the interaction of more than one property. It will also do all the validations on individual 128 | * properties, so if you only want to call one method on your card to validate it after setting all the 129 | * properties, call this one 130 | * 131 | * @param outError a pointer to an NSError that, after calling this method, will be populated with an error if the card is not valid. See StripeError.h for 132 | possible values 133 | * 134 | * @return whether or not the card is valid. 135 | * @deprecated use STPCardValidator instead. 136 | */ 137 | - (BOOL)validateCardReturningError:(NSError * __nullable * __nullable)outError __attribute__((deprecated("Use STPCardValidator instead."))); 138 | 139 | @end 140 | 141 | // This method is used internally by Stripe to deserialize API responses and exposed here for convenience and testing purposes only. You should not use it in 142 | // your own code. 143 | @interface STPCard (PrivateMethods) 144 | - (nonnull instancetype)initWithAttributeDictionary:(nonnull NSDictionary *)attributeDictionary; 145 | @end 146 | -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPPaymentCardTextField.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPPaymentCardTextField.h 3 | // Stripe 4 | // 5 | // Created by Jack Flintermann on 7/16/15. 6 | // Copyright (c) 2015 Stripe, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class STPPaymentCardTextField; 12 | 13 | /** 14 | * This protocol allows a delegate to be notified when a payment text field's contents change, which can in turn be used to take further actions depending on the validity of its contents. 15 | */ 16 | @protocol STPPaymentCardTextFieldDelegate 17 | @optional 18 | /** 19 | * Called when either the card number, expiration, or CVC changes. At this point, one can call -isValid on the text field to determine, for example, whether or not to enable a button to submit the form. Example: 20 | 21 | - (void)paymentCardTextFieldDidChange:(STPPaymentCardTextField *)textField { 22 | self.paymentButton.enabled = textField.isValid; 23 | } 24 | 25 | * 26 | * @param textField the text field that has changed 27 | */ 28 | - (void)paymentCardTextFieldDidChange:(nonnull STPPaymentCardTextField *)textField; 29 | 30 | @end 31 | 32 | 33 | /** 34 | * STPPaymentCardTextField is a text field with similar properties to UITextField, but specialized for collecting credit/debit card information. It manages multiple UITextFields under the hood to collect this information. It's designed to fit on a single line, and from a design perspective can be used anywhere a UITextField would be appropriate. 35 | */ 36 | @interface STPPaymentCardTextField : UIControl 37 | 38 | /** 39 | * @see STPPaymentCardTextFieldDelegate 40 | */ 41 | @property(nonatomic, weak, nullable) id delegate; 42 | 43 | /** 44 | * The font used in each child field. Default is [UIFont systemFontOfSize:18]. Set this property to nil to reset to the default. 45 | */ 46 | @property(nonatomic, copy, null_resettable) UIFont *font UI_APPEARANCE_SELECTOR; 47 | 48 | /** 49 | * The text color to be used when entering valid text. Default is [UIColor blackColor]. Set this property to nil to reset to the default. 50 | */ 51 | @property(nonatomic, copy, null_resettable) IBInspectable UIColor *textColor UI_APPEARANCE_SELECTOR; 52 | 53 | /** 54 | * The text color to be used when the user has entered invalid information, such as an invalid card number. Default is [UIColor redColor]. Set this property to nil to reset to the default. 55 | */ 56 | @property(nonatomic, copy, null_resettable) IBInspectable UIColor *textErrorColor UI_APPEARANCE_SELECTOR IBInspectable; 57 | 58 | /** 59 | * The text placeholder color used in each child field. Default is [UIColor lightGreyColor]. Set this property to nil to reset to the default. On iOS 7 and above, this will also set the color of the card placeholder icon. 60 | */ 61 | @property(nonatomic, copy, null_resettable) IBInspectable UIColor *placeholderColor UI_APPEARANCE_SELECTOR IBInspectable; 62 | 63 | /** 64 | * The border color for the field. Default is [UIColor lightGreyColor]. Can be nil (in which case no border will be drawn). 65 | */ 66 | @property(nonatomic, copy, nullable) IBInspectable UIColor *borderColor UI_APPEARANCE_SELECTOR IBInspectable; 67 | 68 | /** 69 | * The width of the field's border. Default is 1.0. 70 | */ 71 | @property(nonatomic, assign) IBInspectable CGFloat borderWidth UI_APPEARANCE_SELECTOR IBInspectable; 72 | 73 | /** 74 | * The corner radius for the field's border. Default is 5.0. 75 | */ 76 | @property(nonatomic, assign) IBInspectable CGFloat cornerRadius UI_APPEARANCE_SELECTOR IBInspectable; 77 | 78 | /** 79 | * This behaves identically to setting the inputAccessoryView for each child text field. 80 | */ 81 | @property(nonatomic, strong, nullable) UIView *inputAccessoryView; 82 | 83 | /** 84 | * Causes the text field to begin editing. Presents the keyboard. 85 | * 86 | * @return Whether or not the text field successfully began editing. 87 | * @see UIResponder 88 | */ 89 | - (BOOL)becomeFirstResponder; 90 | 91 | /** 92 | * Causes the text field to stop editing. Dismisses the keyboard. 93 | * 94 | * @return Whether or not the field successfully stopped editing. 95 | * @see UIResponder 96 | */ 97 | - (BOOL)resignFirstResponder; 98 | 99 | /** 100 | * Resets all of the contents of all of the fields. If the field is currently being edited, the number field will become selected. 101 | */ 102 | - (void)clear; 103 | 104 | /** 105 | * Whether or not the form currently contains a valid card number, expiration date, and CVC. 106 | * @see STPCardValidator 107 | */ 108 | @property(nonatomic, readonly, getter=isValid)BOOL valid; 109 | 110 | /** 111 | * Enable/disable selecting or editing the field. Useful when submitting card details to Stripe. 112 | */ 113 | @property(nonatomic, getter=isEnabled) BOOL enabled; 114 | 115 | /** 116 | * The current card number displayed by the field. May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid. 117 | */ 118 | @property(nonatomic, readonly, nullable) NSString *cardNumber; 119 | 120 | /** 121 | * The current expiration month displayed by the field (1 = January, etc). May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid. 122 | */ 123 | @property(nonatomic, readonly) NSUInteger expirationMonth; 124 | 125 | /** 126 | * The current expiration year displayed by the field, modulo 100 (e.g. the year 2015 will be represented as 15). May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid. 127 | */ 128 | @property(nonatomic, readonly) NSUInteger expirationYear; 129 | 130 | /** 131 | * The current card CVC displayed by the field. May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid. 132 | */ 133 | @property(nonatomic, readonly, nullable) NSString *cvc; 134 | 135 | @end 136 | 137 | #pragma mark - PaymentKit compatibility 138 | 139 | #pragma clang diagnostic push 140 | #pragma clang diagnostic ignored "-Wdeprecated" 141 | 142 | __attribute__((deprecated("This class is provided only for backwards-compatibility with PaymentKit. You shouldn't use it - use STPCard instead."))) 143 | @interface PTKCard : STPCard 144 | @end 145 | 146 | @class PTKView; 147 | 148 | __attribute__((deprecated("This protocol is provided only for backwards-compatibility with PaymentKit. You shouldn't use it - use STPPaymentCardTextFieldDelegate instead."))) 149 | @protocol PTKViewDelegate 150 | 151 | @optional 152 | - (void)paymentView:(nonnull PTKView *)paymentView withCard:(nonnull PTKCard *)card isValid:(BOOL)valid; 153 | 154 | @end 155 | 156 | __attribute__((deprecated("This class is provided only for backwards-compatibility with PaymentKit. You shouldn't use it - use STPPaymentCardTextField instead."))) 157 | @interface PTKView : STPPaymentCardTextField 158 | @property(nonatomic, weak, nullable)iddelegate; 159 | @property(nonatomic, readonly, nonnull) PTKCard *card; 160 | @end 161 | 162 | #pragma clang diagnostic pop 163 | -------------------------------------------------------------------------------- /src/ios/CDVApplePay.m: -------------------------------------------------------------------------------- 1 | #import "CDVApplePay.h" 2 | #import 3 | #import 4 | #import 5 | #import 6 | #import 7 | #import 8 | 9 | 10 | @implementation CDVApplePay 11 | 12 | - (void) pluginInitialize { 13 | [super pluginInitialize]; 14 | 15 | NSLog(@"Initialize Apple Pay Plugin"); 16 | NSString * StripePublishableKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"StripePublishableKey"]; 17 | merchantId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"ApplePayMerchant"]; 18 | [Stripe setDefaultPublishableKey:StripePublishableKey]; 19 | } 20 | 21 | - (void)dealloc 22 | { 23 | 24 | } 25 | 26 | - (void)onReset 27 | { 28 | 29 | } 30 | 31 | - (void)setMerchantId:(CDVInvokedUrlCommand*)command 32 | { 33 | merchantId = [command.arguments objectAtIndex:0]; 34 | NSLog(@"ApplePay set merchant id to %@", merchantId); 35 | } 36 | 37 | - (void)getAllowsApplePay:(CDVInvokedUrlCommand*)command 38 | { 39 | if (merchantId == nil) { 40 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Please call setMerchantId() with your Apple-given merchant ID."]; 41 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 42 | return; 43 | } 44 | 45 | PKPaymentRequest *request = [Stripe 46 | paymentRequestWithMerchantIdentifier:merchantId]; 47 | 48 | // Configure a dummy request 49 | NSString *label = @"Premium Llama Food"; 50 | NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:@"10.00"]; 51 | request.paymentSummaryItems = @[ 52 | [PKPaymentSummaryItem summaryItemWithLabel:label 53 | amount:amount] 54 | ]; 55 | 56 | if ([Stripe canSubmitPaymentRequest:request]) { 57 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"user has apple pay"]; 58 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 59 | } else { 60 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"user does not have apple pay"]; 61 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 62 | } 63 | } 64 | 65 | - (void)getStripeToken:(CDVInvokedUrlCommand*)command 66 | { 67 | 68 | if (merchantId == nil) { 69 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Please call setMerchantId() with your Apple-given merchant ID."]; 70 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 71 | return; 72 | } 73 | 74 | PKPaymentRequest *request = [Stripe 75 | paymentRequestWithMerchantIdentifier:merchantId]; 76 | 77 | // Configure your request here. 78 | NSString *label = [command.arguments objectAtIndex:1]; 79 | NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:[command.arguments objectAtIndex:0]]; 80 | request.paymentSummaryItems = @[ 81 | [PKPaymentSummaryItem summaryItemWithLabel:label 82 | amount:amount] 83 | ]; 84 | 85 | NSString *cur = [command.arguments objectAtIndex:2]; 86 | request.currencyCode = cur; 87 | 88 | callbackId = command.callbackId; 89 | 90 | if ([Stripe canSubmitPaymentRequest:request]) { 91 | PKPaymentAuthorizationViewController *paymentController; 92 | paymentController = [[PKPaymentAuthorizationViewController alloc] 93 | initWithPaymentRequest:request]; 94 | paymentController.delegate = self; 95 | [self.viewController presentViewController:paymentController animated:YES completion:nil]; 96 | } else { 97 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"You dont have access to ApplePay"]; 98 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 99 | return; 100 | } 101 | 102 | } 103 | 104 | - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller 105 | didAuthorizePayment:(PKPayment *)payment 106 | completion:(void (^)(PKPaymentAuthorizationStatus))completion { 107 | [self handlePaymentAuthorizationWithPayment:payment completion:completion]; 108 | } 109 | 110 | - (void)handlePaymentAuthorizationWithPayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion { 111 | 112 | [[STPAPIClient sharedClient] createTokenWithPayment:payment completion:^(STPToken *token, NSError *error) { 113 | if (error) { 114 | completion(PKPaymentAuthorizationStatusFailure); 115 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"couldn't get a stripe token from STPAPIClient"]; 116 | [self.commandDelegate sendPluginResult:result callbackId:callbackId]; 117 | return; 118 | } else { 119 | 120 | NSString* brand; 121 | 122 | switch (token.card.brand) { 123 | case STPCardBrandVisa: 124 | brand = @"Visa"; 125 | break; 126 | case STPCardBrandAmex: 127 | brand = @"American Express"; 128 | break; 129 | case STPCardBrandMasterCard: 130 | brand = @"MasterCard"; 131 | break; 132 | case STPCardBrandDiscover: 133 | brand = @"Discover"; 134 | break; 135 | case STPCardBrandJCB: 136 | brand = @"JCB"; 137 | break; 138 | case STPCardBrandDinersClub: 139 | brand = @"Diners Club"; 140 | break; 141 | case STPCardBrandUnknown: 142 | brand = @"Unknown"; 143 | break; 144 | } 145 | 146 | NSDictionary* card = @{ 147 | @"id": token.card.cardId, 148 | @"brand": brand, 149 | @"last4": [NSString stringWithFormat:@"%@", token.card.last4], 150 | @"exp_month": [NSString stringWithFormat:@"%lu", token.card.expMonth], 151 | @"exp_year": [NSString stringWithFormat:@"%lu", token.card.expYear] 152 | }; 153 | 154 | NSDictionary* message = @{ 155 | @"id": token.tokenId, 156 | @"card": card 157 | }; 158 | 159 | completion(PKPaymentAuthorizationStatusSuccess); 160 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: message]; 161 | [self.commandDelegate sendPluginResult:result callbackId:callbackId]; 162 | } 163 | 164 | }]; 165 | } 166 | 167 | 168 | - (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller { 169 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"user cancelled apple pay"]; 170 | [self.commandDelegate sendPluginResult:result callbackId:callbackId]; 171 | [self.viewController dismissViewControllerAnimated:YES completion:nil]; 172 | } 173 | 174 | @end -------------------------------------------------------------------------------- /src/ios/Stripe.framework/Versions/A/Headers/STPAPIClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // STPAPIClient.h 3 | // StripeExample 4 | // 5 | // Created by Jack Flintermann on 12/18/14. 6 | // Copyright (c) 2014 Stripe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | static NSString *const __nonnull STPSDKVersion = @"5.1.0"; 13 | 14 | @class STPBankAccount, STPCard, STPToken; 15 | 16 | /** 17 | * A callback to be run with the response from the Stripe API. 18 | * 19 | * @param token The Stripe token from the response. Will be nil if an error occurs. @see STPToken 20 | * @param error The error returned from the response, or nil in one occurs. @see StripeError.h for possible values. 21 | */ 22 | typedef void (^STPCompletionBlock)(STPToken * __nullable token, NSError * __nullable error); 23 | 24 | /** 25 | A top-level class that imports the rest of the Stripe SDK. This class used to contain several methods to create Stripe tokens, but those are now deprecated in 26 | favor of STPAPIClient. 27 | */ 28 | @interface Stripe : NSObject 29 | 30 | /** 31 | * Set your Stripe API key with this method. New instances of STPAPIClient will be initialized with this value. You should call this method as early as 32 | * possible in your application's lifecycle, preferably in your AppDelegate. 33 | * 34 | * @param publishableKey Your publishable key, obtained from https://stripe.com/account/apikeys 35 | * @warning Make sure not to ship your test API keys to the App Store! This will log a warning if you use your test key in a release build. 36 | */ 37 | + (void)setDefaultPublishableKey:(nonnull NSString *)publishableKey; 38 | 39 | /// The current default publishable key. 40 | + (nullable NSString *)defaultPublishableKey; 41 | @end 42 | 43 | /// A client for making connections to the Stripe API. 44 | @interface STPAPIClient : NSObject 45 | 46 | /** 47 | * A shared singleton API client. Its API key will be initially equal to [Stripe defaultPublishableKey]. 48 | */ 49 | + (nonnull instancetype)sharedClient; 50 | - (nonnull instancetype)initWithPublishableKey:(nonnull NSString *)publishableKey NS_DESIGNATED_INITIALIZER; 51 | 52 | /** 53 | * @see [Stripe setDefaultPublishableKey:] 54 | */ 55 | @property (nonatomic, copy, nullable) NSString *publishableKey; 56 | 57 | /** 58 | * The operation queue on which to run the url connection and delegate methods. Cannot be nil. @see NSURLConnection 59 | */ 60 | @property (nonatomic, nonnull) NSOperationQueue *operationQueue; 61 | 62 | @end 63 | 64 | #pragma mark Bank Accounts 65 | 66 | @interface STPAPIClient (BankAccounts) 67 | 68 | /** 69 | * Converts an STPBankAccount object into a Stripe token using the Stripe API. 70 | * 71 | * @param bankAccount The user's bank account details. Cannot be nil. @see https://stripe.com/docs/api#create_bank_account_token 72 | * @param completion The callback to run with the returned Stripe token (and any errors that may have occurred). 73 | */ 74 | - (void)createTokenWithBankAccount:(nonnull STPBankAccount *)bankAccount completion:(__nullable STPCompletionBlock)completion; 75 | 76 | @end 77 | 78 | #pragma mark Credit Cards 79 | 80 | @interface STPAPIClient (CreditCards) 81 | 82 | /** 83 | * Converts an STPCard object into a Stripe token using the Stripe API. 84 | * 85 | * @param card The user's card details. Cannot be nil. @see https://stripe.com/docs/api#create_card_token 86 | * @param completion The callback to run with the returned Stripe token (and any errors that may have occurred). 87 | */ 88 | - (void)createTokenWithCard:(nonnull STPCard *)card completion:(nullable STPCompletionBlock)completion; 89 | 90 | @end 91 | 92 | // These methods are used internally and exposed here only for the sake of writing tests more easily. You should not use them in your own application. 93 | @interface STPAPIClient (PrivateMethods) 94 | 95 | - (void)createTokenWithData:(nonnull NSData *)data completion:(nullable STPCompletionBlock)completion; 96 | 97 | @end 98 | 99 | #pragma mark - Deprecated Methods 100 | // These methods are deprecated. You should instead use STPAPIClient to create tokens. 101 | // Example: [Stripe createTokenWithCard:card completion:completion]; 102 | // becomes [[STPAPIClient sharedClient] createTokenWithCard:card completion:completion]; 103 | @interface Stripe (Deprecated) 104 | 105 | /** 106 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 107 | *connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 108 | * 109 | * @param card The user's card details. @see STPCard 110 | * @param handler Code to run when the user's card has been turned into a Stripe token. 111 | * @deprecated Use STPAPIClient instead. 112 | */ 113 | + (void)createTokenWithCard:(nonnull STPCard *)card completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 114 | 115 | /** 116 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 117 | *connection will run on the main queue. 118 | * 119 | * @param card The user's card details. @see STPCard 120 | * @param publishableKey The API key to use to authenticate with Stripe. Get this at https://stripe.com/account/apikeys . 121 | * @param handler Code to run when the user's card has been turned into a Stripe token. 122 | * @deprecated Use STPAPIClient instead. 123 | */ 124 | + (void)createTokenWithCard:(nonnull STPCard *)card publishableKey:(nonnull NSString *)publishableKey completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 125 | 126 | /** 127 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. 128 | * 129 | * @param card The user's card details. @see STPCard 130 | * @param queue The operation queue on which to run the URL connection. @see NSURLConnection 131 | * @param handler Code to run when the user's card has been turned into a Stripe token. 132 | * @deprecated Use STPAPIClient instead. 133 | */ 134 | + (void)createTokenWithCard:(nonnull STPCard *)card operationQueue:(nonnull NSOperationQueue *)queue completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 135 | 136 | /** 137 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. 138 | * 139 | * @param card The user's card details. @see STPCard 140 | * @param publishableKey The API key to use to authenticate with Stripe. Get this at https://stripe.com/account/apikeys . 141 | * @param queue The operation queue on which to run the URL connection. @see NSURLConnection 142 | * @param handler Code to run when the user's card has been turned into a Stripe token. 143 | * @deprecated Use STPAPIClient instead. 144 | */ 145 | + (void)createTokenWithCard:(nonnull STPCard *)card 146 | publishableKey:(nonnull NSString *)publishableKey 147 | operationQueue:(nonnull NSOperationQueue *)queue 148 | completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 149 | 150 | /** 151 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 152 | *connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 153 | * 154 | * @param bankAccount The user's bank account details. @see STPBankAccount 155 | * @param handler Code to run when the user's card has been turned into a Stripe token. 156 | * @deprecated Use STPAPIClient instead. 157 | */ 158 | + (void)createTokenWithBankAccount:(nonnull STPBankAccount *)bankAccount completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 159 | 160 | /** 161 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 162 | *connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 163 | * 164 | * @param bankAccount The user's bank account details. @see STPBankAccount 165 | * @param publishableKey The API key to use to authenticate with Stripe. Get this at https://stripe.com/account/apikeys . 166 | * @param handler Code to run when the user's card has been turned into a Stripe token. 167 | * @deprecated Use STPAPIClient instead. 168 | */ 169 | + (void)createTokenWithBankAccount:(nonnull STPBankAccount *)bankAccount 170 | publishableKey:(nonnull NSString *)publishableKey 171 | completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 172 | 173 | /** 174 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 175 | *connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 176 | * 177 | * @param bankAccount The user's bank account details. @see STPBankAccount 178 | * @param queue The operation queue on which to run the URL connection. @see NSURLConnection 179 | * @param handler Code to run when the user's card has been turned into a Stripe token. 180 | * @deprecated Use STPAPIClient instead. 181 | */ 182 | + (void)createTokenWithBankAccount:(nonnull STPBankAccount *)bankAccount 183 | operationQueue:(nonnull NSOperationQueue *)queue 184 | completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 185 | 186 | /** 187 | * Securely convert your user's credit card details into a Stripe token, which you can then safely store on your server and use to charge the user. The URL 188 | *connection will run on the main queue. Uses the value of [Stripe defaultPublishableKey] for authentication. 189 | * 190 | * @param bankAccount The user's bank account details. @see STPBankAccount 191 | * @param publishableKey The API key to use to authenticate with Stripe. Get this at https://stripe.com/account/apikeys . 192 | * @param queue The operation queue on which to run the URL connection. @see NSURLConnection 193 | * @param handler Code to run when the user's card has been turned into a Stripe token. 194 | * @deprecated Use STPAPIClient instead. 195 | */ 196 | + (void)createTokenWithBankAccount:(nonnull STPBankAccount *)bankAccount 197 | publishableKey:(nonnull NSString *)publishableKey 198 | operationQueue:(nonnull NSOperationQueue *)queue 199 | completion:(nullable STPCompletionBlock)handler __attribute__((deprecated)); 200 | 201 | @end 202 | --------------------------------------------------------------------------------