gpt4 book ai didi

ios - Adyen 支付 iOS 集成

转载 作者:行者123 更新时间:2023-12-04 15:12:37 32 4
gpt4 key购买 nike

有人成功地将 Adyen 支付插件集成到 iOS 应用程序中吗?

我到了它向用户显示付款选项的地步,但选择其中一个选项没有任何作用。我希望它会转到表单以捕获卡的详细信息,但事实并非如此。

如有任何帮助,我们将不胜感激。 View Controller 的代码如下。

import UIKit
import Adyen

extension Dictionary {
func percentEncoded() -> Data? {
return map { key, value in
let escapedKey = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
let escapedValue = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
return escapedKey + "=" + escapedValue
}
.joined(separator: "&")
.data(using: .utf8)
}
}

extension CharacterSet {
static let urlQueryValueAllowed: CharacterSet = {
let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
let subDelimitersToEncode = "!$&'()*+,;="

var allowed = CharacterSet.urlQueryAllowed
allowed.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")
return allowed
}()
}

class ViewController: UIViewController , DropInComponentDelegate {

func didSubmit(_ data: PaymentComponentData, from component: DropInComponent) {

}

func didProvide(_ data: ActionComponentData, from component: DropInComponent) {

}

func didFail(with error: Error, from component: DropInComponent) {

}

func didCancel(component: PresentableComponent, from dropInComponent: DropInComponent){

}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

}

@IBAction func buttonCLicked(_ sender: UIButton) {
setUpAdyen()
}

func setUpAdyen() {

let url = URL(string: "xxxxxxx")!

var request = URLRequest(url: url)

request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"

let parameters: [String: Any] = [
"amount": 1000,
]

request.httpBody = parameters.percentEncoded()

print(request.httpBody ?? "")

let task = URLSession.shared.dataTask(with: request) { data, response, error in

guard let data = data,
let response = response as? HTTPURLResponse,
error == nil else {
print("error", error ?? "Unknown error")
return
}

guard (200 ... 299) ~= response.statusCode else {
print("statusCode should be 2xx, but is \(response.statusCode)")
print("response = \(response)")
return
}

do {

let paymentMethods = try JSONDecoder().decode(PaymentMethods.self, from: data)

let configuration = DropInComponent.PaymentMethodsConfiguration()

configuration.clientKey = "xxxxxxxx"

let dropInComponent = DropInComponent(paymentMethods: paymentMethods,paymentMethodsConfiguration: configuration)

dropInComponent.delegate = self

dropInComponent.environment = .test

dropInComponent.payment = Payment(amount: Payment.Amount(value: 1000, currencyCode: "GBP"))

DispatchQueue.main.async {
self.present(dropInComponent.viewController, animated: true)
}

} catch {
print(error)
}

}

task.resume()


}

}

支付选项显示,但点击其中任何一个都没有任何反应,因为它应该显示屏幕以捕获卡的详细信息。

最佳答案

应该保留 dropInComponent


class ViewController: UIViewController , DropInComponentDelegate {

private var dropInComponent: DropInComponent?

...

func setUpAdyen() {
...

let dropInComponent = DropInComponent(paymentMethods: paymentMethods,paymentMethodsConfiguration: configuration)
self.dropInComponent = dropInComponent

...

}
}

关于ios - Adyen 支付 iOS 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64941944/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com