如何在 iOS 应用程序中集成 Atom 支付网关?
How to integrate Atom payment gateway in iOS app?
我是扩展名为 .a 的静态库的新手,我正在尝试将原子技术支付网关实现到 iOS 应用程序。他们提供 2 个文件 1.libAtomPayLib(Live).a
2.libAtomPayLib(UAT).a
还有一个非常简短的文档
根据他们的文档,我已将 .a 文件添加到项目中,"added other link flag"“$(OTHER_LDFLAGS) -ObjC”。
文档中有一点我没看懂
Add Bundle ”resourcesLib” in Build Phases selecting your project target(Copy Bundle Resources).
以下代码来自文档
#import <UIKit/UIKit.h>
#import "nb.h"
#import "card.h"
#import "NSString+DES.h"
#import "NSData+DES.h"
@interface ViewController : UIViewController <NSXMLParserDelegate,nbDelegate,cardDelegate>
{
NSXMLParser *parser;
}
@property (weak, nonatomic) IBOutlet UIButton *InitiateRequest;
@property (nonatomic,retain) NSXMLParser *parser;
-(IBAction)callVC:(id)sender;//Call for all transaction
@end
我试图在 viewcontroller.h 文件中使用此代码,但出现错误 "nb.h not found"
我猜这些 headers 来自图书馆,如果它与项目正确链接 nb.h 将随处可用。我还添加了文档详细信息
ATOM Mobile SDK Integration
Atom 移动集成旨在使您能够通过移动应用程序处理付款。
集成类型:- Non-Seamless:
设置
• Create new Group in your project hierarch & add all the files from “payAtom” in it.
• Select your Project from Left Panel
• Go to targets tab & select the application
• Go to Build Setting & select Basic & Combined Tabs
• Add the following property as shown below
如果找不到“其他链接器标志”,则可以执行以下步骤
• Select the project file from the project navigator on the far left side of the window.
• Select the target for where you want to add the linker flag.
• Select the "Build Settings" tab
• Choose "All" to show all Build Settings.
• Scroll down to the "Linking" section, and double-click to the right of where it says "Other Linking Flags".
• A box will appear, Click on the "+" button to add a new linker flag.
• Type "$(OTHER_LDFLAGS) -ObjC" (no quotes) and press enter.
• Add Bundle ”resourcesLib” in Build Phases selecting your project target(Copy Bundle Resources).
积分:
• Merchant will design a screen wherein he will accept all the required fields including the bank detail, payment options and card details.
• Pass the data to Library as follows in the same format:
ViewController.h 文件
#import <UIKit/UIKit.h>
#import "nb.h"
#import "card.h"
#import "NSString+DES.h"
#import "NSData+DES.h"
@interface ViewController : UIViewController <NSXMLParserDelegate,nbDelegate,cardDelegate>
{
NSXMLParser *parser;
}
@property (weak, nonatomic) IBOutlet UIButton *InitiateRequest;
@property (nonatomic,retain) NSXMLParser *parser;
-(IBAction)callVC:(id)sender;//Call for all transaction
@end
ViewController.m 文件
#import "ViewController.h"
#import "nb.h"
#import "card.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize parser;
• (void)viewDidLoad { [super viewDidLoad];
}
• (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)callVC:(id)sender
{
nb *netB = [[nb alloc] init]; netB.myDelegate = self; netB.loginid=@"459"; netB.txnscamt=@"0"; netB.loginid=@"459"; netB.password=@"Test@123"; netB.prodid=@"NSE"; netB.txncurr=@"INR"; netB.clientcode=@"001"; netB.custacc=@"100000036600"; netB.amt=@"100.000"; netB.txnid=@"9Q6";//unique each time
netB.date=@"23/08/2010%2011:57:00";//unique each time netB.bankid=@"2001"; netB.ru=@"https://paynetzuat.atomtech.in/paynetz/param"; [self presentViewController:netB animated:YES completion:nil];
}
-(void)secondviewcontrollerDissmissed:(NSString *)stringToFirst
{
NSString *getResult; getResult = stringToFirst;
NSLog(@"received---->%@",getResult); //This will return status success or Fail of Transaction
}
@end
通常静态库(如 libAtomPayLib.a)只包含代码,而不包含 UI 资源(如图像、声音、字体、配置文件等)。解决它的一种方法是提供资源包。 bundle 实际上是一个包含各种文件的目录,但在 macOS 上(使用 Finder 等程序)它看起来像一个文件(例如 resourcesLib.bundle)。如果你只是将这样的文件添加到你的项目 Xcode (默认情况下)实际上会将它添加到你的 "copy bundle resources" 阶段。您可以通过转到 TARGETS、select 您的目标、打开 "Build Phases" 并展开 "Copy Bundle Resources".
来检查这一点
构建应用程序后,您实际上可以通过展开 "Products" 组、right-click 您的 Example.app "Show in Finder" 来确保捆绑包已被复制,然后右键单击该文件和 "Show Package Contents"。您应该看到在您的应用中复制了哪些文件,包括资源包。
如果您将一些 "test.a" 静态库文件添加到您的项目中,默认的 Xcode 行为是将其添加到 "Linked Frameworks and Libraries" 列表中。您可以通过转到 TARGETS 来验证它,select 您的目标,打开 "General" 并向下滚动到 "Linked Frameworks and Libraries".
这是atom支付网关的问题,他们应该提供.h文件和.a文件,但下载的文件中没有。因此,我使用了另一种解决方案,即使用 Web 视图来集成 Atom 支付网关。我创建了一个 class 以获得付款 url。此方法使用同项目网站中使用的网页支付网关。
import Foundation
import Alamofire
import SwiftyXMLParser
class PaymentData {
var totalPrice:String
var taxId:String
var userName:String
var email:String
var mobile:String
var userId:String
var currentDateTimeString:String
init(totalPrice:String) {
let time = Date().timeIntervalSince1970
let taxId = "WVC"+String(time)
let userId = UserDefaults.standard.string(forKey: "UserId")
let name = UserDefaults.standard.string(forKey: "full_name")
let phone = UserDefaults.standard.string(forKey: "phone")
let email = UserDefaults.standard.string(forKey: "email")
self.totalPrice = totalPrice
self.taxId = taxId
self.userId = userId!
self.email = email!
self.mobile = phone!
self.userName = name!
self.currentDateTimeString = NSDate().getStringWith(format: "dd/MM/yyyy")!
}
func getVenderUrl()->String{
// Create vender url using user details
var vVenderURL:String = "https://payment.atomtech.in/paynetz/epi/fts?login=test&pass=test@123&ttype=NBFundTransfer&prodid=test&amt=" + "\(totalPrice)"+"&txncurr=INR&txnscamt=0&ru=https://www.test.in/payment-success&clientcode=lisas00940&txnid="+"\(taxId)"+"&date="+"\(currentDateTimeString)"+"&udf1="+"\(userName)"+"&udf2="+"\(email)"+"&udf3="+"\(mobile)"+"&udf4=Bangalore&custacc="+"\(userId)"+"";
vVenderURL = vVenderURL.replacingOccurrences(of: " ", with: "%20")
print(vVenderURL)
return vVenderURL
}
func getRedirectUrl(callBack:@escaping (URL)->Void){
// get url to load in webview
var xmlURL:String = ""
var xmlttype:String = ""
var xmltoken:String = ""
var xmltempTxnId:String = ""
var xmltxnStage:String = ""
let headers: HTTPHeaders = [
"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
"Accept": "application/json"
]
// Call api for get payment url to load in webview
Alamofire.request(getVenderUrl(), method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers)
.responseString { response in
var statusCode = response.response?.statusCode
switch response.result {
case .success:
// parsing xml data recieved from response, and extracting element required for generating the payment url
if let string = response.result.value {
print("XML: \(string)")
let xml = try! XML.parse(string)
print(xml["MMP","MERCHANT","RESPONSE"])
xmlURL = xml["MMP","MERCHANT","RESPONSE","url"].text!
let params = xml["MMP","MERCHANT","RESPONSE","param"]
for param in params {
if (param[0].attributes["name"]) == "ttype" {
xmlttype = param.text!
}
if (param[0].attributes["name"]) == "tempTxnId" {
xmltempTxnId = param.text!
}
if (param[0].attributes["name"]) == "token" {
xmltoken = param.text!
}
if (param[0].attributes["name"]) == "txnStage" {
xmltxnStage = param.text!
}
}
// creating payment url from extracted data
var Atom2Request:String = "\(xmlURL)" + "?ttype=" + "\(xmlttype)" + "&tempTxnId=" + "\(xmltempTxnId)" + "&token=" + "\(xmltoken)" + "&txnStage=" + "\(xmltxnStage)";
Atom2Request = Atom2Request.replacingOccurrences(of: " ", with: "%20") //(" ", "%20");
print("ATOM 2nd Request URl" + "\(Atom2Request)")
callBack(URL.init(string: Atom2Request)!)
}
case .failure(let error):
statusCode = error._code // statusCode private
print("status code is: \(String(describing: statusCode))")
print(error)
}
}
}
}
此 class 有助于创建用于为 atom 支付网关生成 url 的数据,下一步是将此 url 加载到网络视图
创建一个视图控制器并在其中添加web视图,并添加以下代码
@IBOutlet weak var paymentWebView: UIWebView!
var paymentAmount:String?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Payment Gateway"
if paymentAmount != nil {
let paymentData = PaymentData.init(totalPrice: paymentAmount!)
paymentData.getRedirectUrl(callBack:{ url in
let request = URLRequest(url: url)
self.paymentWebView.loadRequest(request)
})
}
}
在 Swift 中实施 Atom 支付网关非常简单..
只需按照简单的步骤操作即可。
从下面link下载SDK。
https://www.atomtech.in/help-resource/payment-gateway-integration-kits
解压缩文件。
运行 iOS 设备中 Xcode 中的‘testSample.xcodeproj’。别担心代码在 Objective C.
创建您自己的 Swift 项目。
在您的项目中创建一个文件夹“include”。在“include”文件夹下创建另一个嵌套文件夹“AtomPayLib”。
将所有 header 文件 (.h) 包括“resourceLib.bundle”从 testSample 项目拖到您的项目文件夹“AtomPayLib”。不要忘记选中目标的复选框。
只需为您的项目创建任何 Objective C ViewController class。 Xcode 会要求您将 Bridging Header 添加到您的项目中。选择是。 Bridging header 添加后删除新创建的 Objective class.
在桥接 Header 中添加以下两行。
#import“nb.h”
#import“card.h”
在你的“AtomPay”按钮里面,你可以在你的项目中任何你喜欢的地方写下面的代码。
委托方法也写在它的正下方。不要忘记添加方法。还要将一致性 'nbDelegate' 添加到 ViewController class.
//MARK: Atom Payment
@IBAction func atomPay(_ sender: Any)
{
var netB = nb()
netB.discriminator = "All"
netB.myDelegate = self
netB.merchantId = "197"
netB.txnscamt = "0"
netB.loginid = "197"
netB.password = "Test@123"
netB.txncurr = "INR"
netB.clientcode="007"
netB.custacc="100000036600"
netB.amt = "100.00"
netB.txnid = "013";
netB.date = "23/08/2019 11:57:00"
netB.bankid = "2001"
netB.signatureRequest = "KEY123657234"
netB.signatureResponse = "KEYRESP123657234"
netB.prodid = "NSE"
netB.isLive = false
netB.ru = "https://paynetzuat.atomtech.in/mobilesdk/param"
// netB.customerName = "ABC";
// netB.customerEmailID = "abc@gmail.com";
// netB.customerMobileNo = "5555555555";
// netB.billingAddress = "Kolkata";
// netB.optionalUdf9 = "Peter";
self.present(netB, animated: true) {
print("Completed...")
}
}
func secondviewcontrollerDissmissed(_ stringForFirst: String!,
withResponseKeys ResponseKeyArray: NSMutableArray!, andResponseValues
ResponseValueArray: NSMutableArray!) {
print("received---->%@",stringForFirst!)
let deadlineTime = DispatchTime.now() + .seconds(5)
DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
print("test")
//code to be executed on the main queue after delay
}
}
运行 您的 iOS 设备中的应用程序。
干杯!
我是扩展名为 .a 的静态库的新手,我正在尝试将原子技术支付网关实现到 iOS 应用程序。他们提供 2 个文件 1.libAtomPayLib(Live).a 2.libAtomPayLib(UAT).a 还有一个非常简短的文档
根据他们的文档,我已将 .a 文件添加到项目中,"added other link flag"“$(OTHER_LDFLAGS) -ObjC”。
文档中有一点我没看懂
Add Bundle ”resourcesLib” in Build Phases selecting your project target(Copy Bundle Resources).
以下代码来自文档
#import <UIKit/UIKit.h>
#import "nb.h"
#import "card.h"
#import "NSString+DES.h"
#import "NSData+DES.h"
@interface ViewController : UIViewController <NSXMLParserDelegate,nbDelegate,cardDelegate>
{
NSXMLParser *parser;
}
@property (weak, nonatomic) IBOutlet UIButton *InitiateRequest;
@property (nonatomic,retain) NSXMLParser *parser;
-(IBAction)callVC:(id)sender;//Call for all transaction
@end
我试图在 viewcontroller.h 文件中使用此代码,但出现错误 "nb.h not found" 我猜这些 headers 来自图书馆,如果它与项目正确链接 nb.h 将随处可用。我还添加了文档详细信息
ATOM Mobile SDK Integration
Atom 移动集成旨在使您能够通过移动应用程序处理付款。
集成类型:- Non-Seamless:
设置
• Create new Group in your project hierarch & add all the files from “payAtom” in it.
• Select your Project from Left Panel
• Go to targets tab & select the application
• Go to Build Setting & select Basic & Combined Tabs
• Add the following property as shown below
如果找不到“其他链接器标志”,则可以执行以下步骤
• Select the project file from the project navigator on the far left side of the window.
• Select the target for where you want to add the linker flag.
• Select the "Build Settings" tab
• Choose "All" to show all Build Settings.
• Scroll down to the "Linking" section, and double-click to the right of where it says "Other Linking Flags".
• A box will appear, Click on the "+" button to add a new linker flag.
• Type "$(OTHER_LDFLAGS) -ObjC" (no quotes) and press enter.
• Add Bundle ”resourcesLib” in Build Phases selecting your project target(Copy Bundle Resources).
积分:
• Merchant will design a screen wherein he will accept all the required fields including the bank detail, payment options and card details.
• Pass the data to Library as follows in the same format:
ViewController.h 文件
#import <UIKit/UIKit.h>
#import "nb.h"
#import "card.h"
#import "NSString+DES.h"
#import "NSData+DES.h"
@interface ViewController : UIViewController <NSXMLParserDelegate,nbDelegate,cardDelegate>
{
NSXMLParser *parser;
}
@property (weak, nonatomic) IBOutlet UIButton *InitiateRequest;
@property (nonatomic,retain) NSXMLParser *parser;
-(IBAction)callVC:(id)sender;//Call for all transaction
@end
ViewController.m 文件
#import "ViewController.h"
#import "nb.h"
#import "card.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize parser;
• (void)viewDidLoad { [super viewDidLoad];
}
• (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)callVC:(id)sender
{
nb *netB = [[nb alloc] init]; netB.myDelegate = self; netB.loginid=@"459"; netB.txnscamt=@"0"; netB.loginid=@"459"; netB.password=@"Test@123"; netB.prodid=@"NSE"; netB.txncurr=@"INR"; netB.clientcode=@"001"; netB.custacc=@"100000036600"; netB.amt=@"100.000"; netB.txnid=@"9Q6";//unique each time
netB.date=@"23/08/2010%2011:57:00";//unique each time netB.bankid=@"2001"; netB.ru=@"https://paynetzuat.atomtech.in/paynetz/param"; [self presentViewController:netB animated:YES completion:nil];
}
-(void)secondviewcontrollerDissmissed:(NSString *)stringToFirst
{
NSString *getResult; getResult = stringToFirst;
NSLog(@"received---->%@",getResult); //This will return status success or Fail of Transaction
}
@end
通常静态库(如 libAtomPayLib.a)只包含代码,而不包含 UI 资源(如图像、声音、字体、配置文件等)。解决它的一种方法是提供资源包。 bundle 实际上是一个包含各种文件的目录,但在 macOS 上(使用 Finder 等程序)它看起来像一个文件(例如 resourcesLib.bundle)。如果你只是将这样的文件添加到你的项目 Xcode (默认情况下)实际上会将它添加到你的 "copy bundle resources" 阶段。您可以通过转到 TARGETS、select 您的目标、打开 "Build Phases" 并展开 "Copy Bundle Resources".
来检查这一点构建应用程序后,您实际上可以通过展开 "Products" 组、right-click 您的 Example.app "Show in Finder" 来确保捆绑包已被复制,然后右键单击该文件和 "Show Package Contents"。您应该看到在您的应用中复制了哪些文件,包括资源包。
如果您将一些 "test.a" 静态库文件添加到您的项目中,默认的 Xcode 行为是将其添加到 "Linked Frameworks and Libraries" 列表中。您可以通过转到 TARGETS 来验证它,select 您的目标,打开 "General" 并向下滚动到 "Linked Frameworks and Libraries".
这是atom支付网关的问题,他们应该提供.h文件和.a文件,但下载的文件中没有。因此,我使用了另一种解决方案,即使用 Web 视图来集成 Atom 支付网关。我创建了一个 class 以获得付款 url。此方法使用同项目网站中使用的网页支付网关。
import Foundation
import Alamofire
import SwiftyXMLParser
class PaymentData {
var totalPrice:String
var taxId:String
var userName:String
var email:String
var mobile:String
var userId:String
var currentDateTimeString:String
init(totalPrice:String) {
let time = Date().timeIntervalSince1970
let taxId = "WVC"+String(time)
let userId = UserDefaults.standard.string(forKey: "UserId")
let name = UserDefaults.standard.string(forKey: "full_name")
let phone = UserDefaults.standard.string(forKey: "phone")
let email = UserDefaults.standard.string(forKey: "email")
self.totalPrice = totalPrice
self.taxId = taxId
self.userId = userId!
self.email = email!
self.mobile = phone!
self.userName = name!
self.currentDateTimeString = NSDate().getStringWith(format: "dd/MM/yyyy")!
}
func getVenderUrl()->String{
// Create vender url using user details
var vVenderURL:String = "https://payment.atomtech.in/paynetz/epi/fts?login=test&pass=test@123&ttype=NBFundTransfer&prodid=test&amt=" + "\(totalPrice)"+"&txncurr=INR&txnscamt=0&ru=https://www.test.in/payment-success&clientcode=lisas00940&txnid="+"\(taxId)"+"&date="+"\(currentDateTimeString)"+"&udf1="+"\(userName)"+"&udf2="+"\(email)"+"&udf3="+"\(mobile)"+"&udf4=Bangalore&custacc="+"\(userId)"+"";
vVenderURL = vVenderURL.replacingOccurrences(of: " ", with: "%20")
print(vVenderURL)
return vVenderURL
}
func getRedirectUrl(callBack:@escaping (URL)->Void){
// get url to load in webview
var xmlURL:String = ""
var xmlttype:String = ""
var xmltoken:String = ""
var xmltempTxnId:String = ""
var xmltxnStage:String = ""
let headers: HTTPHeaders = [
"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
"Accept": "application/json"
]
// Call api for get payment url to load in webview
Alamofire.request(getVenderUrl(), method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers)
.responseString { response in
var statusCode = response.response?.statusCode
switch response.result {
case .success:
// parsing xml data recieved from response, and extracting element required for generating the payment url
if let string = response.result.value {
print("XML: \(string)")
let xml = try! XML.parse(string)
print(xml["MMP","MERCHANT","RESPONSE"])
xmlURL = xml["MMP","MERCHANT","RESPONSE","url"].text!
let params = xml["MMP","MERCHANT","RESPONSE","param"]
for param in params {
if (param[0].attributes["name"]) == "ttype" {
xmlttype = param.text!
}
if (param[0].attributes["name"]) == "tempTxnId" {
xmltempTxnId = param.text!
}
if (param[0].attributes["name"]) == "token" {
xmltoken = param.text!
}
if (param[0].attributes["name"]) == "txnStage" {
xmltxnStage = param.text!
}
}
// creating payment url from extracted data
var Atom2Request:String = "\(xmlURL)" + "?ttype=" + "\(xmlttype)" + "&tempTxnId=" + "\(xmltempTxnId)" + "&token=" + "\(xmltoken)" + "&txnStage=" + "\(xmltxnStage)";
Atom2Request = Atom2Request.replacingOccurrences(of: " ", with: "%20") //(" ", "%20");
print("ATOM 2nd Request URl" + "\(Atom2Request)")
callBack(URL.init(string: Atom2Request)!)
}
case .failure(let error):
statusCode = error._code // statusCode private
print("status code is: \(String(describing: statusCode))")
print(error)
}
}
}
}
此 class 有助于创建用于为 atom 支付网关生成 url 的数据,下一步是将此 url 加载到网络视图
创建一个视图控制器并在其中添加web视图,并添加以下代码
@IBOutlet weak var paymentWebView: UIWebView!
var paymentAmount:String?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Payment Gateway"
if paymentAmount != nil {
let paymentData = PaymentData.init(totalPrice: paymentAmount!)
paymentData.getRedirectUrl(callBack:{ url in
let request = URLRequest(url: url)
self.paymentWebView.loadRequest(request)
})
}
}
在 Swift 中实施 Atom 支付网关非常简单..
只需按照简单的步骤操作即可。
从下面link下载SDK。 https://www.atomtech.in/help-resource/payment-gateway-integration-kits
解压缩文件。
运行 iOS 设备中 Xcode 中的‘testSample.xcodeproj’。别担心代码在 Objective C.
创建您自己的 Swift 项目。
在您的项目中创建一个文件夹“include”。在“include”文件夹下创建另一个嵌套文件夹“AtomPayLib”。
将所有 header 文件 (.h) 包括“resourceLib.bundle”从 testSample 项目拖到您的项目文件夹“AtomPayLib”。不要忘记选中目标的复选框。
只需为您的项目创建任何 Objective C ViewController class。 Xcode 会要求您将 Bridging Header 添加到您的项目中。选择是。 Bridging header 添加后删除新创建的 Objective class.
在桥接 Header 中添加以下两行。 #import“nb.h” #import“card.h”
在你的“AtomPay”按钮里面,你可以在你的项目中任何你喜欢的地方写下面的代码。 委托方法也写在它的正下方。不要忘记添加方法。还要将一致性 'nbDelegate' 添加到 ViewController class.
//MARK: Atom Payment @IBAction func atomPay(_ sender: Any) { var netB = nb() netB.discriminator = "All" netB.myDelegate = self netB.merchantId = "197" netB.txnscamt = "0" netB.loginid = "197" netB.password = "Test@123" netB.txncurr = "INR" netB.clientcode="007" netB.custacc="100000036600" netB.amt = "100.00" netB.txnid = "013"; netB.date = "23/08/2019 11:57:00" netB.bankid = "2001" netB.signatureRequest = "KEY123657234" netB.signatureResponse = "KEYRESP123657234" netB.prodid = "NSE" netB.isLive = false netB.ru = "https://paynetzuat.atomtech.in/mobilesdk/param" // netB.customerName = "ABC"; // netB.customerEmailID = "abc@gmail.com"; // netB.customerMobileNo = "5555555555"; // netB.billingAddress = "Kolkata"; // netB.optionalUdf9 = "Peter"; self.present(netB, animated: true) { print("Completed...") }
}
func secondviewcontrollerDissmissed(_ stringForFirst: String!, withResponseKeys ResponseKeyArray: NSMutableArray!, andResponseValues ResponseValueArray: NSMutableArray!) { print("received---->%@",stringForFirst!) let deadlineTime = DispatchTime.now() + .seconds(5) DispatchQueue.main.asyncAfter(deadline: deadlineTime) { print("test") //code to be executed on the main queue after delay }
}
运行 您的 iOS 设备中的应用程序。
干杯!