18910140161

iOS-48-Stripe海外支付最详细流程和代码

顺晟科技

2021-06-16 10:30:22

340

海外支付需求

我们需要使用海外支付进行银行卡的管理和支付功能。给我们的要求是使用条纹,可以使用其提供的管理页面。可以使用银行卡列表页面、添加页面等。

步:在委托类中注册键

[Stripe setdefaultpublished key :s tri key];

stripeKey为关键,注意键可以设置测试环境和线上环境的钥匙。

第二步:在需要的页面唤起银行卡列表页

STPPaymentConfiguration * config=[STPPaymentConfiguration共享配置];

配置。additionalpaymentoptions=stppaymentoptions type none;

配置。必选billingaddressfields=stpbillingaddressfields no ne;配置。PublishableKey=stripeKey

stripe client * manager=[stripe client sharedAPIClient];

strpcustomercontext * customer context=[[strpcustomercontext alloc]InitwithKeyProvider : manager];

stppaymentOptionview controller * VC=[[stppaymentOptionview controller alloc]initwith configuration : config theme :[stpt血红素默认值主题]客户上下文:客户上下文代表:[NGPayManager共享实例]];

[[外部管理器获取控制器]。导航控制器推送视图控制器:vc动画: yes];

StripeAPIClient为引用stpccustomerephemeragencypprovider的协议类,为了种类去进行验证操作

StripeAPIClient.h

#导入基础/基础。h

#导入条纹/条纹。h

@ interface StripeAPIClient : nsobjectstpccustomerephemeragenkyprovider

/**

初始化种类用户信息

*/

(实例类型)sharedAPIClient

/**

STPEphemeralKeyProvider代理方法,初始化后会自动调用

@param apiVersion当前应用程序接口的版本

@param完成成功回调

*/

-(void)createcustomerkeywithapiversion :(NSString *)API版本完成:(StPjsonresponsecompletionBlock)完成;

@end

StripeAPIClient.m

#import 'StripeAPIClient.h '

#导入条纹/条纹。h

static stripe client * _ manager=nil;

@ interface StripeAPIClient()

@end

@实现StripeAPIClient

(instancetype)sharedAPIClient{

if(!_经理){

_ manager=[[Stripeapiclient alloc]init];

}

退货管理器(_ m)

}

-(void)CreatecustomerKeyWithAppLiversion :(NSString *)API版本完成:(StPjsonresponsecompletionBlock)完成{

[ngordersevermanager postapicardephemeralkeywith DIC : @ { } success:^(id _非空响应对象){

调度_异步(调度_获取_主_ queue(),^{

NGHideHud

});

ns字典* TMPDIC=(ns字典*)响应对象;

完成(tmpDic,无);

} failure:^(nserror * _非空错误){

调度_异步(调度_获取_主_ queue(),^{

NGHideHud

警告消息([错误本地化描述]);

});

}];

}

@end

-(void)createcustomerkeywithapiversion :(NSString *)API版本完成:(StPjsonresponsecompletionBlock)完成

种类的验证是通过这个回调完成的

其中调用自己后台服务器的接口去绑定个人信息和银行卡信息的关系,返回给客户端相关数据提供给种类的sdk。

{

associated_objects'=(

{

id=

类型=客户

}

);

created=1585708749

expires=1585712349

id=

live模式=1;

对象='短命_ key ';

秘密=

}

后台的返回样式是这样。

选择银行卡的代理回调

#pragma标记委托

-(void)paymentoptions视图控制器:(stppaymentoptionview controller *)paymentoptions视图控制器

didfailtoloadwitherror :(NSError *)错误{

}

-(void)paymentoptions视图控制器id cancel :(stppaymentoptionview controller *)paymentoptions视图控制器{

NSMutableDictionary * DIC=[NSMutableDictionary字典];

[NGPayManager共享实例]。银行卡选择块(DIC);

[paymentoptions视图控制器。导航控制器popviewcontrolerimated d : yes];

}

-(void)paymentoptions视图控制器id finish :(stppaymentoptionview controller *)paymentoptions视图控制器{

}

-(void)paymentoptions视图控制器:(stppaymentopview controller *)paymentoptions视图控制器未选择paymentoptions :(idSTPPaymentOption)paymentoptions {

STPPaymentMethod *支付方式=(STPPaymentMethod *)paymentOption;

NSMutableDictionary * DIC=[NSMutableDictionary字典];

【DIC设置对象:支付方式。stripe id forkey : @ ' payCardId '];

NSString * brand=@

切换(付款方式。卡片。品牌){

案例STPCardBrandVisa:

品牌=@ '签证

打破;

STPCardBrandJCB:

品牌=@ ' JCB

打破;

STPCardBrandAmex:

品牌=@ '美国运通

打破;

案例STPCardBrandUnknown:

品牌=@ '未知;

打破;

STPCardBrandDiscover:号案件

品牌=@ '发现;

打破;

案件STPCardBrandUnionPay:

品牌=@ '银联;

打破;

STPCardBrandDinersClub:号案件

品牌=@ ' DinersClub

打破;

STPCardBrandMasterCard:号案件

品牌=@ '万事达卡;

打破;

默认值:

打破;

}

【DIC SetObject :品牌forkey : @ '品牌'】;

[DIC SetObject :付款方式。卡片。last 4 forkey : @ ' last 4 '];

【DIC设置对象:【整数:内ns数支付方式。卡片。ex p month]forkey : @ ' ex p month '];

【DIC设置对象:【整数:内ns数支付方式。卡片。expYear]forkey : @ ' expYear '];

[NGPayManager共享实例]。银行卡选择块(DIC);

[paymentoptions视图控制器。导航控制器popviewcontrolerimated d : yes];

}

选择完银行卡后进行支付操作

将选择的银行卡信息提交给后台,其中需要的是paymentMethod.stripeId参数

后台将种类需要的支付信息返回给客户端,客户端拉起支付操作。

(void)BankPayWithOrderdic :(NSdictionary *)Orderdic回调:(NGPayCompletionblock)完成块{

//收集卡详情

stppaymentparams * paymentmentmententparams=[[stppaymentparams alloc]initwitchclientsecret :[common tools getstringwithdic : order DIC key : @ ' client secret ']];

paymentmententparams。支付方式=[常用工具getstringwithdic : order DIC key : @ ' payment method '];

//提交付款

STPPaymentHandler * paymentHandler=[STPPaymentHandler共享处理程序];

[paymenthandler confirmation payment : paymententityparams with authentication context :[ngpaymanager共享instance]completion:^(stppaymenthandleractionstatus状态,stppaymentintent * paymentintent,NSError *error) {

调度_异步(调度_获取_主_ queue(),^{

开关(状态){

案例stppaymenthandleractionstatusfailed : {

调度_异步(调度_获取_主_ queue(),^{

NGHideHud

警告消息([错误本地化描述]);

completionBlock(@ { @ ' success ' : @ ' 0 ' });

});

打破;

}

案例stppaymenthandleractionstatuscanceled : {

调度_异步(调度_获取_主_ queue(),^{

NGHideHud

警告消息([错误本地化描述]);

completionBlock(@ { @ ' success ' : @ ' 1 ' });

});

打破;

}

case stppaymenthandlectionstatuscceed : {

completionBlock(@ { @ ' success ' : @ ' 2 ' });

打破;

}

默认值:

打破;

}

});

}];

}

选择控制器

-(uiviewcontroler *)authenticationmentingviewcontroler {

return[lysupermanager Getcurcontroller];

}

支付完成

进行订单查询即可

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航