这是一个 iOS SDK,它允许您从客户端端处理支付,并生成 Ingenico NPS 服务器上的付款,而不需要在您的服务器上通过任何敏感支付信息。
工作原理
*阅读此内容: Objective C,Swift
当客户提交您的支付表单时,nps-ios-sdk 将客户敏感支付详细信息发送到 Ingenico NPS 服务器进行加密和存储,并为您提供 PaymentMethodToken 以使用我们的 API 完成支付流程。
使用这个一次性使用的 PaymentMethodToken,您可以使用我们的 API 做任何需要敏感支付信息的事情。通过此机制,您永远不会处理任何敏感支付信息,您的 PCI 范围将大大缩小。
基本流程
- 使用 NPS.js 安全地收集敏感支付详细信息
- 将这些支付详细信息转换为一次性使用的 PaymentMethodToken
- 将 PaymentMethodToken 提交到您的服务器。
- 使用 销售/授权 方法与 psp_VaultReference.PaymentMethodToken 完成支付。
要使用 nps-ios-sdk 处理支付,您应该遵循以下步骤
- 客户设备请求商户后端生成一个 clientSession ID
- 商户后端在 Ingenico NPS Latam 上执行 CreateClientSession()
- Ingenico NPS Latam 使用 clientsession ID响应 CreateClientSession()
- 将 clientsession ID 发送到客户设备
- 客户端设备显示信用卡输入数据表单
- 客户使用信用卡数据填写表单
- 客户设备使用 clientsession ID 请求 Ingenico NPS Latam 上的 CreatePaymentMethodToken(),发送所有敏感支付详细信息。此令牌是一次性使用的令牌。
- Ingenico NPS Latam 使用 PaymentMethodToken(此令牌只能使用一次)进行响应
- 客户设备将 PaymentMethodToken 发送到商户后端
- 商户后端使用收到的令牌请求任何类型的支付
- Ingenico NPS Latam 响应已完成的支付
- 商户后端将支付响应发送到客户设备
- 最终,客户设备将支付响应显示给客户
安装
要开始使用,请按照以下步骤在您iOS API上进行安装
CocoaPod
将其添加到您的Podfile
pod 'npsSdk', '1.0.18'
安装
pod install
集成
导入Nps模块
#import "Nps.h"
配置
为了能够使用 nps-ios-sdk 方法,您需要获取一个类的新实例,并传递您的客户端会话和商户ID作为参数。按照以下部分获取参数。
Nps *nps = [[Nps alloc]initWithEnvironment:NPSSANDBOX];
nps.merchantId = @"__YOUR_NPS_MERCHANT_ID__";
nps.clientSession = @"__YOUR_NPS_CLIENT_SESSION__";
配置您的客户端会话
您应该在构造函数中将客户端会话配置为使用 nps-ios-sdk 在与 NPS 通信时识别您的站点。为此,请在 Nps 类的构造函数中将值作为参数设置。记得在准备创建真实费用时,将沙盒中的客户端会话调用替换为生产域名。
您可以通过调用 webservice 方法 "NpsCreateClientSession" 获取您的客户端会话 创建客户端会话(请求) 创建客户端会话(响应)
配置您的商户ID
您需要配置商户ID以便开始使用nps-ios-sdk在与其通信时识别您的网站。为此,请使用NPS提供的商户ID。记住,当您准备好创建真实交易时,请将沙箱环境中的商户ID替换为生产环境中的商户ID。
卡片脱敏
nps-ios-sdk提供的主要功能是卡片脱敏,这使得您能够安全地将卡信息发送到 Ingenico NPS,而无需接触您的服务器,从而减少PCI义务。一旦生成了PaymentMethoToken,您就可以安全地将它传递到您的服务器上,处理支付或将它保存为可重复使用的PaymentMethodId。
通过传递包含支付方式数据的卡对象来创建PaymentMethodToken。也可以传递可选的账单对象
Nps *nps = [[Nps alloc]initWithEnvironment:NPSSANDBOX];
nps.merchantId = @"__YOUR_NPS_MERCHANT_ID__";
nps.clientSession = @"__YOUR_NPS_CLIENT_SESSION__";
NpsCardDetails *card = [[NpsCardDetails alloc]init];
card.number = @"4507990000000010";
card.holderName = @"JOHN DOE";
card.securityCode = @"123";
card.expirationDate = @"1909";
NpsBilling *billing = [[NpsBilling alloc]init];
billing.pspPerson.firstName = @"JOHN";
billing.pspPerson.lastName = @"Smith";
billing.pspPerson.dateOfBirth = @"1987-01-01";
billing.pspPerson.gender = @"M";
billing.pspPerson.nationality = @"ARG";
billing.pspPerson.idType = @"DNI";
billing.pspPerson.idNumber = @"32123123";
billing.pspPerson.phoneNumber1 = @"4123-1234";
billing.pspPerson.phoneNumber2 = @"4123-5678";
billing.pspAddress.additionalInfo = @"JOHN";
billing.pspAddress.city = @"Smith";
billing.pspAddress.stateProvince = @"Buenos Aires";
billing.pspAddress.country = @"M";
billing.pspAddress.zipCode = @"ARG";
billing.pspAddress.street = @"DNI";
billing.pspAddress.houseNumber = @"32123123";
[nps createPaymentMethodToken:card
billingDetails:billing
methodResponse:^(NpsCreatePaymentMethodTokenResponse* methodResponse, NSError *error) {
if(!error){
NSLog(@"%@", [methodResponse responseCod]);
}
}];
methodResponse将接收作为一个对象的PaymentMethodToken响应。此对象的主要属性是methodResponse.id,您需要通过API处理支付。
应使用** *error **进行错误处理。常见的错误可能是由开发时的错误或无效的支付详情输入数据引起的。
从PaymentMethodId脱敏卡片
您可以使用存储的PaymentMethodId和卡安全码创建PaymentMethodToken;仅在部分国家需要卡安全码。PaymentMethodId是一个持久的PaymentMethodToken,通过调用服务器端方法CreatePaymentMethod (请求)和CreateCustomer (请求)创建,recache的行为和能力已从原始createPaymentMethodToken方法克隆。
通过传递包含PaymentMethod数据的PaymentMethod对象来回显一个PaymentMethodToken
Nps *nps = [[Nps alloc]initWithEnvironment:NPSSANDBOX];
nps.merchantId = @"__YOUR_NPS_MERCHANT_ID__";
nps.clientSession = @"__YOUR_NPS_CLIENT_SESSION__";
Billing *billingDetailss = [[Billing alloc]init];
billingDetailss.pspPerson.firstName = @"JOHN DOE";
[nps recachePaymentMethodToken:@"kWRZGcAxy5D7MoB6BDACugHYrlFzP9Eg"
cardSecurityCode:@"123"
billingDetails:billingDetailss
methodResponse:^(NpsRecachePaymentMethodTokenResponse *methodResponse, NSError *error) {
if (!error){
NSLog(@"%@", [methodResponse responseCod]);
}
}];
卡验证器
表单验证是强制性的。在表单提交时,必须按照以下顺序执行nps.validateCardNumber验证
card.validateCardHolderName
该验证器检查卡片上的名称是否是有效的名称,且长度不超过2至26个字符。
if([nps validateCardHolderName:@"JOHN DOE"]) {
NSLog(@"Holder name is valid");
}else{
NSLog(@"Holder Name is invalid");
}
card.validateCardNumber
if([nps validateCardNumber:@"4111000000000010"]) {
NSLog(@"Card number is valid");
}else{
NSLog(@"Card number is invalid");
}
查询IIN
通过检索用IIN的产品ID,可以验证卡片号。此方法还将调用webservice方法"GetIINDetails": GetIINDetails (Request) GetIINDetails (Response)
Nps *nps = [[Nps alloc]initWithEnvironment:SANDBOX];
[nps getIIDetails:@"424242"
postDateTime:@"2016-12-01 12:00:00"
methodResponse:^(NpsGetIINDetailsResponse *methodResponse, NSError *error) {
if(!error){
NSLog(@"%@", [methodResponse responseCod]);
}
}];
card.validateCardExpDate
该验证器检查截止日期是否有效且未过期。
if([nps validateCardExpDate:2017 month:12]) {
NSLog(@"Expiration date is valid");
}else{
NSLog(@"Expiration date is invalid");
}
card.validateCardSecurityCode
该验证器检查安全码是否为有效的整数(3-4个字符)。
if([nps validateCardSecurityCode:@"123"]) {
NSLog(@"CVV is valid");
}else{
NSLog(@"CVV is invalid");
}
卡片分期付款
如果您需要特殊情况下查看客户的分期付款金额的卡片分期付款,请参考以下示例。
Nps *nps = [[Nps alloc]initWithEnvironment:SANDBOX];
nps.merchantId = @"__YOUR_NPS_MERCHANT_ID__";
nps.clientSession = @"__YOUR_NPS_CLIENT_SESSION__";
[nps getInstallmentsOptions:@"100"
product:@"14"
currency:@"152"
country:@"CHL"
numPayments:@"2"
paymentMethodToken:@"kkvKuOfD2bNKXCBYDkunIRqImvNFNxB3"
methodResponse:^(NpsGetInstallmentsOptionsResponse *methodResponse, NSError *error) {
if (!error){
NSLog(@"%@", [methodResponse responseCod]);
for (Installments *inst in [methodResponse installments]){
NSLog(@"%@", [inst installmentAmount]);
NSLog(@"%@", [inst interestRate]);
NSLog(@"%@", [inst numPayments]);
}
}
}];
设备指纹
通过此功能,您可以收集关于您最终用户的设备信息。客户端生成一个黑盒,其中包含所有可用的设备信息。然后,您可以使用 psp_CustomerAdditionalDetails.DeviceFingerPrint API 字段将黑盒(设备指纹)从您的后端服务器返回给 NPS,以用于欺诈检测目的。
Nps.getDeviceFingerprint
此方法允许您获取最终用户设备的设备指纹。
[Nps getDeviceFingerprint];