当我试图使用Github(https://github.com/square/SquareRegisterSDK-iOS)中的Square SDK进行支付时,我无法在Square POS应用程序中找到从我的应用程序传递的金额。
请找出我实际遵循的以下步骤。
我已经从下面的git hub链接下载了Square Register SDK。
https://github.com/square/SquareRegisterSDK-iOS
我使用cocoa pods运行了应用程序,并且在我的项目中成功地安装了pod文件。
我已在“我的应用程序”部分的“我的客户端登录”中创建了一个测试应用程序。
应用程序名称:MyApp
应用程序Id:xxxxxxxxxxxx(我的应用程序Id来自Square Dashboard)
我已经在Register Api部分注册了Bundle Id和回调Url
iOS应用程序包Id:我的包Id
iOS应用程序URL方案:我的回拨URL
因为我的账户是通过申请接收付款的。
现在回到我的代码,我刚刚接受了Square Register SDK--->SwiftCharge类方法。
请找出下面的代码,我已使用的收费,请让我知道任何更正,从我的结束。
导入SquareRegisterSDK
导入UIKit
让您的客户id=“xxxxxxxxx”
让你的callback URL=URL(字符串:“MyApp://callback”)!
枚举节:Int{
案例数量=0,支持的类型,可选字段,设置

init?(at indexPath: IndexPath) {
    self.init(rawValue: indexPath.section)
}

}
设所有投标类型:[SCCAPIRequestTenderTypes]=[.card、.cash、.other、.squareGiftCard、.cardOnFile]
扩展字符串{
var nilIfEmpty:字符串?{
还我空吗?无:自我
}
}
类ViewController:UIViewController{
var supportedTenderTypes: SCCAPIRequestTenderTypes = .card
var clearsDefaultFees = false
var returnAutomaticallyAfterPayment = true

@IBOutlet weak var currencyField: UITextField!
@IBOutlet weak var amountField: UITextField!

@IBOutlet weak var notesField: UITextField!
@IBOutlet weak var userInfoStringField: UITextField!
@IBOutlet weak var merchantIDField: UITextField!
@IBOutlet weak var customerIDField: UITextField!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func awakeFromNib() {
    super.awakeFromNib()

    // Always set the client ID before creating your first API request.
    SCCAPIRequest.setClientID(yourClientID)
}


@IBAction func charge(sender: AnyObject) {

    let currencyCodeString = "USD"
    let amountString = "500"

    let amount: SCCMoney
    guard let amountCents = Int(amountString) else {
        showErrorMessage(title: "Invalid Amount", message: "\(amountString) is not a valid amount.")
        return
    }

    do {
        amount = try SCCMoney(amountCents: amountCents, currencyCode: currencyCodeString)
    } catch let error as NSError {
        showErrorMessage(title: "Invalid Amount", error: error)
        return
    }

    let userInfoString = "Radhachandan"
    let merchantID = ""
    let customerID = ""
    let notes = "Sample Test"

    let request: SCCAPIRequest
    do {
        request = try SCCAPIRequest(callbackURL: yourCallbackURL,
                                    amount: amount,
                                    userInfoString: userInfoString,
                                    merchantID: merchantID,
                                    notes: notes,
                                    customerID: customerID,
                                    supportedTenderTypes: supportedTenderTypes,
                                    clearsDefaultFees: clearsDefaultFees,
                                    returnAutomaticallyAfterPayment: returnAutomaticallyAfterPayment)
    } catch let error as NSError {
        showErrorMessage(title: "Invalid Amount", error: error)
        return
    }

    do {
        try SCCAPIConnection.perform(request)

    } catch let error as NSError {


showErrorMessage(title: "Cannot Perform Request", error: error)
        return
    }
   }


private func showErrorMessage(title: String, error: NSError) {
    showErrorMessage(title: title, message: error.localizedDescription)
}

private func showErrorMessage(title: String, message: String) {
    let alertView = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alertView.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
    present(alertView, animated: true, completion: nil)
}

}
到目前为止,它被重定向到Square Point of Sale应用程序,但它没有显示我通过的金额。
我们将非常感谢您的反馈。

最佳答案

尝试如下修改代码:

...
let userInfoString = "Radhachandan"
    let merchantID = nil
    let customerID = nil
    let notes = "Sample Test"
...

当为这些参数传递空字符串时,您已经提醒我们有一个错误,我们将很快进行修复。

关于ios - 使用Square SDK Swift 3付款,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42953667/

10-14 21:54