3

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

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

任何帮助将不胜感激。视图控制器的代码如下。

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()

        
    }
  
}

付款选项显示,但当它应该显示屏幕以捕获卡详细信息时,单击其中任何一个都不会执行任何操作。

4

1 回答 1

2

dropInComponent应该坚持。


class ViewController: UIViewController , DropInComponentDelegate {

     private var dropInComponent: DropInComponent?

     ...
     
     func setUpAdyen() {
         ...

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

         ...
                
     }
}

于 2020-11-30T16:20:17.920 回答