[英]How to integrate Atom payment gateway in iOS app?
我是帶有 extension.a 的靜態庫的新手,我正在嘗試將原子技術支付網關植入 iOS 應用程序。 他們提供了 2 個文件 1.libAtomPayLib(Live).a 2.libAtomPayLib(UAT).a 和一個非常簡短的文檔
根據他們的文檔,我添加了一個文件到項目中,“添加了其他鏈接標志”“$(OTHER_LDFLAGS) -ObjC”。
文檔中有一點我不明白
在構建階段中添加 Bundle “resourcesLib” 選擇您的項目目標(復制 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” 我猜這些標頭來自庫,如果它與項目正確鏈接 nb.h 將隨處可用。 我還添加了文檔詳細信息
ATOM 移動 SDK 集成
Atom 移動集成旨在使您能夠通過移動應用程序處理付款。
集成類型:- 非無縫:
設置
• 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
如果找不到“Other Linker Flags”,則可以執行以下這些步驟
• 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
這是atom支付網關的問題,他們應該提供ah文件和.a文件,但下載的文件中沒有。 因此,我使用了另一種解決方案,即使用 Web 視圖來集成 Atom 支付網關。 我創建了一個用於獲取付款網址的類。 此方法使用同一項目網站中使用的網絡支付網關。
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)
}
}
}
}
此類有助於創建用於為原子支付網關生成 url 的數據,下一步是將此 url 加載到 web 視圖
創建一個view controller並在其中添加web view,並添加如下代碼
@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 支付網關非常簡單……
只需按照簡單的步驟操作。
從以下鏈接下載 SDK。 https://www.atomtech.in/help-resource/payment-gateway-integration-kits
解壓縮文件。
在 iOS 設備的 Xcode 中運行“testSample.xcodeproj”。 不用擔心代碼在 Objective C 中。
創建您自己的 Swift 項目。
在您的項目中創建一個文件夾“include”。 在“include”文件夾下創建另一個嵌套文件夾“AtomPayLib”。
將所有頭文件 (.h) 包括“resourceLib.bundle”從 testSample 項目拖到您的項目文件夾“AtomPayLib”。 不要忘記選中目標的復選框。
只需為您的項目創建任何 Objective C ViewController 類。 Xcode 會要求您將 Bridging Header 添加到您的項目中。 選擇是。 添加 Bridging 標頭后,刪除新創建的 Objective 類。
在橋接標頭中添加以下兩行。 #import "nb.h" #import "card.h"
在您的“AtomPay”按鈕內,您可以在項目中的任何地方編寫以下代碼。 委托方法也寫在它的正下方。 不要忘記添加方法。 還將一致性“nbDelegate”添加到您的 ViewController 類。
//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 設備上運行您的應用程序。
干杯!
通常靜態庫(如 libAtomPayLib.a)只包含代碼,而不包含 UI 資源(如圖像、聲音、字體、配置文件等)。 解決它的一種方法是提供資源包。 bundle 實際上是一個包含各種文件的目錄,但在 macOS 上(使用 Finder 等程序)它看起來像一個文件(例如resourcesLib.bundle )。 如果您只是將此類文件添加到您的項目中,Xcode(默認情況下)實際上會將其添加到您的“復制捆綁資源”階段。 您可以通過轉到 TARGETS、選擇您的目標、打開“Build Phases”並展開“Copy Bundle Resources”來檢查這一點。
構建應用程序后,您實際上可以通過展開“產品”組來確保捆綁包已被復制,右鍵單擊您的 Example.app“在 Finder 中顯示”,然后右鍵單擊該文件並“顯示包內容”。 您應該看到在您的應用程序中復制了哪些文件,包括資源包。
如果您將一些“test.a”靜態庫文件添加到您的項目中,默認的 Xcode 行為是將其添加到“鏈接的框架和庫”列表中。 您可以通過轉到目標來驗證它,選擇您的目標,打開“常規”並向下滾動到“鏈接的框架和庫”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.