Skip to content

Instantly share code, notes, and snippets.

@knightbenax
Created March 30, 2019 12:13
Show Gist options
  • Save knightbenax/885e1046e6c98babda0504f38b50b54a to your computer and use it in GitHub Desktop.
Save knightbenax/885e1046e6c98babda0504f38b50b54a to your computer and use it in GitHub Desktop.
let cardParams = PSTCKCardParams.init()
let cardNumber: String = cardNumbField.text!
let ccvFieldString: String = ccvField.text!
cardParams.number = cardNumber
cardParams.cvc = ccvFieldString
cardParams.expYear = 2020
cardParams.expMonth = 9
/*print(cardParams.number)
print(cardParams.cvc)
print(cardParams.expYear)
print(cardParams.expMonth)*/
let transactionParams = PSTCKTransactionParams.init()
transactionParams.email = storeHelper.getUserEmail()
transactionParams.amount = UInt(unitTicketPrice * dataArray.count)
let item : NSMutableArray = ["WinSalvo Ticket Price"]
do {
try transactionParams.setCustomFieldValue("iOS SDK", displayedAs: "Paid Via");
try transactionParams.setCustomFieldValue("WinSalvo Ticket Price", displayedAs: "To Buy");
try transactionParams.setMetadataValue("iOS SDK", forKey: "paid_via");
try transactionParams.setMetadataValueArray(item, forKey: "items");
} catch {
print(error);
}
//print(storeHelper.getUserEmail())
PSTCKAPIClient.shared().chargeCard(cardParams, forTransaction: transactionParams, on: self,
didEndWithError: { (error, reference) -> Void in
//fatalError(error as! String)
self.removeLoader()
self.showAlertMessage(message: "From Paystack: " + error.localizedDescription)
}, didRequestValidation: { (reference) -> Void in
// an OTP was requested, transaction has not yet succeeded
}, didTransactionSuccess: { (reference) -> Void in
//self.changeLoaderMessage(message: "Processing Successful. Saving Card")
self.competitionViewModel.verfiyPayment(competitionId: self.competitionId, data: self.dataArray as NSArray, reference: reference, completion: {(responseObject) in
if (responseObject.success == true){
//show the
let controller = self.storyboard?.instantiateViewController(withIdentifier: "FinalViewController")
self.present(controller!, animated: false, completion: nil)
} else if (responseObject.success == false){
let responseCode = responseObject.data as! Int
let message = responseObject.responseMsg
if (responseCode == 400){
//Check for 400 errors here
self.checkAndDisplayErrors(message: message!)
} else {
self.checkErrorMessage(responseObject: responseObject)
}
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment