iOS integration

To simplify integrating see the following SWIFT sample code.

//Create a credit card payment request

import Foundation

func cardPaymentRequest(amount: UInt, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
    let url = URL(string: "<apiURL>/v1/orders/")!
    
    let username = "<apiKey>" //API key as provided to you
    let password = "" //should remain empty
    
    let authorizationString = username + ":" + password
    let authorizationToken = "Basic " + Data(authorizationString.utf8).base64EncodedString()
    
    let requestData: [String : Any] = [
        "currency": "EUR",
        "amount": 995,
        "merchant_order_id": "EXAMPLE001",
        "description": "Example credit cards order",
        "return_url": "http://www.example.com/",
        "transactions": [
            "payment_method": "credit-card"
        ]
    ]
    
    var request = URLRequest(url: url)
    
    request.httpMethod = "POST"
    
    request.addValue(authorizationToken, forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    
    request.httpBody = try? JSONSerialization.data(withJSONObject: requestData, options: .prettyPrinted)
    
    let dataTask = URLSession.shared.dataTask(with: request, completionHandler: completionHandler)
    dataTask.resume()
}


//Create an IDEAL payment request
func idealPaymentRequest(issuerId: String, amount: UInt, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
    let url = URL(string: "<apiURL>/v1/orders")!
    
    let username = "<apiKey>" //API key as provided to you
    let password = "" //should remain empty
    
    let authorizationString = username + ":" + password
    let authorizationToken = "Basic " + Data(authorizationString.utf8).base64EncodedString()
    
    let requestData: [String : Any] = [
        "currency": "EUR",
        "amount": amount,
        "merchant_order_id": "EXAMPLE002",
        "description": "Example iDEAL order",
        "return_url": "http://www.example.com/",
        "transactions": [
            "payment_method": "ideal",
            "issuer_id": "INGBNL2A"
        ]
    ]
    
    var request = URLRequest(url: url)
    
    request.httpMethod = "POST"
    
    request.addValue(authorizationToken, forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    
    request.httpBody = try? JSONSerialization.data(withJSONObject: requestData, options: .prettyPrinted)
    
    let dataTask = URLSession.shared.dataTask(with: request, completionHandler: completionHandler)
    dataTask.resume()
}


//Create a bank transfer request
func bankTransferRequest(amount: UInt, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
    let url = URL(string: "<apiURL>/v1/orders/")!
    
    let username = "<apiKey>" //API key as provided to you
    let password = "" //should remain empty
    
    let authorizationString = username + ":" + password
    let authorizationToken = "Basic " + Data(authorizationString.utf8).base64EncodedString()
    
    let requestData: [String : Any] = [
        "currency": "EUR",
        "amount": 995,
        "merchant_order_id": "EXAMPLE003",
        "description": "Example bank transfer order",
        "return_url": "http://www.example.com/",
        "transactions": [
            "payment_method": "bank-transfer"
        ]
    ]
    
    var request = URLRequest(url: url)
    
    request.httpMethod = "POST"
    
    request.addValue(authorizationToken, forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    
    request.httpBody = try? JSONSerialization.data(withJSONObject: requestData, options: .prettyPrinted)
    
    let dataTask = URLSession.shared.dataTask(with: request, completionHandler: completionHandler)
    dataTask.resume()
}


// Request order status
func orderStatusRequest(orderID: String, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
    let url = URL(string: "https://api.online.emspay.eu/v1/orders/\(orderID)/")
    
    let username = "<apiKey>" //API key as provided to you
    let password = "" //should remain empty
    
    let authorizationString = username + ":" + password
    let authorizationToken = "Basic " + Data(authorizationString.utf8).base64EncodedString()
    
    if let urlRequest = url{
        var request = URLRequest(url: urlRequest)
        
        request.httpMethod = "GET"
        
        request.addValue(authorizationToken, forHTTPHeaderField: "Authorization")
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        
        let dataTask = URLSession.shared.dataTask(with: request, completionHandler: completionHandler)
        dataTask.resume()
    }
}

cardPaymentRequest(amount: 10) { data, response, error in
    //Handle response
}

idealPaymentRequest(issuerId: "INGBNL2A", amount: 10) { data, response, error in
    //Handle response
}

bankTransferRequest(amount: 10) { data, response, error in
    //Handle response
}

orderStatusRequest(orderID: "967701fe-bc3e-46bf-bb77-29b9b359122c") { (data, response, error) in
    // Handle response
}