Permalink
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
Cannot retrieve contributors at this time.
Cannot retrieve contributors at this time
| // | |
| // STPPaymentMethodTuple.m | |
| // Stripe | |
| // | |
| // Created by Jack Flintermann on 5/17/16. | |
| // Copyright © 2016 Stripe, Inc. All rights reserved. | |
| // | |
| #import "STPPaymentMethodTuple.h" | |
| #import "STPApplePayPaymentMethod.h" | |
| #import "STPCard.h" | |
| NS_ASSUME_NONNULL_BEGIN | |
| @interface STPPaymentMethodTuple() | |
| @property (nonatomic, nullable) id<STPPaymentMethod> selectedPaymentMethod; | |
| @property (nonatomic) NSArray<id<STPPaymentMethod>> *paymentMethods; | |
| @end | |
| @implementation STPPaymentMethodTuple | |
| + (instancetype)tupleWithPaymentMethods:(NSArray<id<STPPaymentMethod>> *)paymentMethods | |
| selectedPaymentMethod:(nullable id<STPPaymentMethod>)selectedPaymentMethod { | |
| STPPaymentMethodTuple *tuple = [self new]; | |
| tuple.paymentMethods = paymentMethods ?: @[]; | |
| tuple.selectedPaymentMethod = selectedPaymentMethod; | |
| return tuple; | |
| } | |
| + (instancetype)tupleWithPaymentMethods:(NSArray<id<STPPaymentMethod>> *)paymentMethods | |
| selectedPaymentMethod:(nullable id<STPPaymentMethod>)selectedPaymentMethod | |
| addApplePayMethod:(BOOL)applePayEnabled { | |
| NSMutableArray *mutablePaymentMethods = paymentMethods.mutableCopy; | |
| id<STPPaymentMethod> _Nullable selected = selectedPaymentMethod; | |
| if (applePayEnabled) { | |
| STPApplePayPaymentMethod *applePay = [STPApplePayPaymentMethod new]; | |
| [mutablePaymentMethods addObject:applePay]; | |
| if (!selected) { | |
| selected = applePay; | |
| } | |
| } | |
| return [self tupleWithPaymentMethods:mutablePaymentMethods.copy | |
| selectedPaymentMethod:selected]; | |
| } | |
| @end | |
| NS_ASSUME_NONNULL_END |