Stripe集成 iOS 端

Stripe集成 iOS 端

因為項目中有遇到需要針對海外用戶集成銀行卡支付功能,經(jīng)過考慮選擇了Stripe。官方文檔地址:https://stripe.com/docs/mobile

因為是海外的,所以文檔暫時沒有中文的,可以下載demo看代碼理解。下面僅給出吊起SDK界面的案例,后面如有需求更改成自己的界面,在做相關(guān)介紹。

/*
這里是吊起銀行卡列表的界面,可以有選擇,添加,編輯刪除等選項,因為是原生SDK界面,所有的操作也都SDK內(nèi)部實現(xiàn)
*/
STPPaymentConfiguration *config = [STPPaymentConfiguration sharedConfiguration];
config.additionalPaymentMethods = STPPaymentMethodTypeNone;     //支持的卡支付類型(銀行卡或者Apple Pay等)
config.requiredBillingAddressFields = STPBillingAddressFieldsNone;//賬單地址等內(nèi)容
      
/*
這里就是比較重要的一步,需要和后端配合。StripeAPIClient是我自己創(chuàng)建的一個類,需要遵循<STPEphemeralKeyProvider>協(xié)議,詳見StripeAPIClient.m文件

init方法可以忽略,自己定義就好,因為后臺需要知道當前用戶的ID,才能創(chuàng)建一個秘鑰
*/
StripeAPIClient *manager = [StripeAPIClient sharedAPIClientWithMemberId:memberId
                                                                        token:token];
STPCustomerContext *customerContext = [[STPCustomerContext alloc] initWithKeyProvider:manager];
      
/*
設(shè)置下代理就可以監(jiān)聽方法了,具體代理方法可以查看<STPPaymentMethodsViewControllerDelegate>
*/
STPPaymentMethodsViewController *viewController = [[STPPaymentMethodsViewController alloc] initWithConfiguration:config theme:STPTheme.defaultTheme customerContext:customerContext delegate:self];

//下面是跳轉(zhuǎn)方法,可以忽略
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
[self presentViewController:nav animated:YES completion:nil];
//  StripeAPIClient.m
//  Stripe
//  用于獲取用戶密令
//
//  Created by yuyang on 2019/3/6.
//

#import "StripeAPIClient.h"
#import <Stripe/Stripe.h>

static StripeAPIClient *_manager = nil;

@interface StripeAPIClient()

@property (nonatomic, copy) NSString *memberId;
@property (nonatomic, copy) NSString *token;

@end

@implementation StripeAPIClient

+ (instancetype)sharedAPIClientWithMemberId:(NSString *)member token:(NSString *)token {
  if (!_manager) {
    _manager = [[StripeAPIClient alloc] init];
    _manager.memberId = member;
    _manager.token = token;
  }
  return _manager;
}

- (void)createCustomerKeyWithAPIVersion:(NSString *)apiVersion completion:(STPJSONResponseCompletionBlock)completion{
  
  /*發(fā)起網(wǎng)絡(luò)請求,拿到后端返給你的信息直接  completion(json,nil);就可以了
    主要后臺返回的json格式,因為Stripe只接收json格式,如果遇到不成功,就檢查下
  */
}

@end

也沒有什么東西,主要就是官方給的Demo不夠明確,有什么問題再討論,代碼放在https://github.com/YuStephen/Stripe-Manager

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容