Skip to content
Hamon Ben Riazy edited this page Apr 25, 2016 · 2 revisions

After making a payment transaction, in some cases you might want to be able to refund a given payment. For this you can use the following code snippet and add your own parameters that are necessary to submit the refund.

do {
    let payment = try judo.payment(myJudoID, amount: oneGBPAmount, reference: validReference).card(validVisaCard)
    
    try payment.completion({ (response, error) -> () in
        if let error = error {
            // handle payment failing error
            return
        }
        
        guard let receiptId = response?.first?.receiptID,
            let amount = response?.first?.amount else {
                // payment was successful
                return
        }
        
        do {
            let refund = try self.judo.refund(receiptId, amount: amount).completion({ (response, error) -> () in
                if let error = error {
                    // handle error
                }
            })
        } catch {
            // handle exception thrown (eg. judoId not luhn valid)
        }
    })
} catch {
    // handle exception thrown (eg. judoId not luhn valid)
}
Clone this wiki locally