- Notifications
You must be signed in to change notification settings - Fork0
youcan-shop/youcan-pay-ios-sdk
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
YouCanPay iOS SDK makes it quick and easy to build an excellent payment experience in your iOS app withYouCan Pay API.
The YouCanPay iOS SDK requires Xcode 11 or later and is compatible with apps targeting iOS 10 or above. We support Catalyst on macOS 10.12 or later.
integration requires endpoints on your server that talk to the YouCanPay API. Use our official libraries for access to the YouCanPay API from your server: the following steps in ourDocumentation will guide you through.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding YouCanPay SDK as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [.package(url: "https://github.com/youcan-shop/youcan-pay-ios-sdk.git")]
The first step is to initialize YouCanPay SDK by creating an instance using the following parameters :pub_key
andlocale
as localizable the default language is en
import YouCanPay/// Initialize YouCanPay SDK/// - Parameter locale: is an optional parameter it can accept (en, ar, fr) to recieve messages with the localization provided it the initializationletycPay=YCPay(pubKey:"YOUR PUB KEY", locale: “en”)
The seller's YouCanPay account public key. This lets us know who is receiving the payment.
After we initialsycPay
we can load the supprted payment methods using:
import YouCanPayycPay.isLoading.observe={ isLoadedinif ycPay.ycpAccountConfig.acceptsCreditCards{ // Credit cards payment method is available}if ycPay.ycpAccountConfig.acceptsCashPlus{ // CashPlus is available}}
When you get ycPay.ycpAccountConfig.acceptsCreditCards == true
it means that Credit Card payment methodis allowed.
letcardInfo=YCPCardInformation(cardHolderName:"NAME", cardNumber:"XXXXXXXXXXXXXXXX", expiryDate:"XX/XX", cvv:"XXX")
You can useycPay.payWithCreditCard
to proceed your payment use as parametrs thetoken_id
it can be generated from your server side and received through an endpoint to the mobile application, to generate a token please refer to theTokenization section.
import YouCanPayprivatefunc pay(){do{ // start loader // initializeletcardInfo=YCPCardInformation(cardHolderName:"NAME", cardNumber:"XXXXXXXXXXXXXXXX", expiryDate:"XX/XX", cvv:"XXX")tryself.ycPay.payWithCreditCard("token_id", cardInfo!,self, successCallback, errorCallback)}catch{ // show error // stop loader}} // onSuccess callbackfunc successCallback(transactionId:String){ // a transaction id is retrieved // stop loader} // onFailure callbackfunc errorCallback(errorMessage:String){ // a error message is retrieved // stop loader}
Once the onSuccess callback invoked it means that the transaction is processeded successfully, a transaction ID will be recieved as a parameter that you can submit with your order details. Similarly, onFailure is called when an error is occurred during the payment, and you get the error message as a parameter to show to customer.
If you you getycPay.ycpAccountConfig.acceptsCashPlus == true
that's mean that you have CashPlus as a payment method
You can useycPay.payWithCashPlus
to proceed your payment use as parametrs thetoken_id
it can be generated from your server side and received through an endpoint to the mobile application, to generate a token please refer to theTokenization section.
import YouCanPayprivatefunc pay(){do{ // start loadertryself.ycPay.payWithCashPlus("token_id", successCallback, errorCallback)}catch{ // show error // stop loader}} // onSuccess callbackfunc successCallback(transactionId:String){ // a transaction id is retrieved // stop loader} // onFailure callbackfunc errorCallback(errorMessage:String){ // a error message is retrieved // stop loader}
YouCan PaySandbox offers an easy way for developers to test YouCan Pay in their test environment.
// setting the sandbox modeycPay.setSandboxMode(false)
Happy coding 🎉