beGateway components for iOS allows you to accept in-app payments
To easy find out how it works:
- Checkout this repository
- Open terminal in
Example
folder - Open begateway.xcworkspace in xCode 10.3 and higher
- Run project and make some action by predefined buttons
- Examine the source code
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate beGateway into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'begateway'
- iOS 11.0+
- Xcode 10.3+
- Swift 5.0+
import begateway
Initilize payment module:
let paymentModule = BeGateway.instance.setup(with: BeGatewayOptions(clientPubKey: "PUBLIC_STORE_KEY"))
You can change public key:
BeGateway.instance.options?.clientPubKey = "PUBLIC_STORE_KEY"
If you want to get current instance of object:
BeGateway.instance
Create BeGatewayRequest object: You can setup your notification_url to become info about payment status:
let request BeGatewayRequest(
// amount
amount: 100.0,
// currency
currency: "USD",
// description
requestDescription: "Test request",
// tracling id
trackingID: "1000000-1"
)
Execute response:
BeGateway.instance.getToken(request: request, completionHandler: {token in
// token for other operation
}, failureHandler:{error in
// out error
print(error)
})
Create BeGatewayRequestCard object:
let card = BeGatewayRequestCard(
number: "2201382000000013",
verificationValue: "123",
expMonth: "02",
expYear: "23",
holder: "WRR",
cardToken: nil,
)
Pay by card without token
BeGateway.instance.pay(
rootController: self,
request: BeGatewayRequest(
amount: 100.0,
currency: "USD",
requestDescription: "Test request",
trackingID: "1000000-1",
card: card
),
completionHandler: {
card in
// BeGatewayCard
print(card)
}, failureHandler: {error in
print(error)
})
Pay by card token
self.card = BeGatewayRequestCard(
number: nil,
verificationValue: nil,
expMonth: nil,
expYear: nil,
holder: nil,
cardToken: "YourCardToken"
)
Payment by card token in background
if self.card?.cardToken != nil { // "YourCardToken"
BeGateway.instance.payByCardTokenInBackground( rootController: self, request: BeGatewayRequest(
amount: Double(self.valueTextField.text ?? "0.0") ?? 0.0,
currency: self.currencyTextField.text ?? "USD",
requestDescription: "Test request",
trackingID: "1000000-1",
card: self.card
), completionHandler: {
//Success handler
}, failureHandler: {error in
//Failure handler
})
}
If gateway return success you can use object BeGatewayCard
```swift
public struct BeGatewayCard {
public let createdAt: Date
public let first1, last4: String
public let brand: String?
}
First you need to setup your project with your merhchant ID. After it you should pass merchant id to BegatewayOptions. Default Apple Pay with input:
options.merchantID = "merchant.org.cocoapods.demo.begateway-Example"
options.merchantName = "Your Company, OOO" // A name of the company that will appear on the customer's billing statement
let _ = BeGateway.instance.setup(with: options)
let request = BeGatewayRequest(amount: Double(self.valueTextField.text ?? "0.0") ?? 0.0,
currency: self.currencyTextField.text?.uppercased() ?? "USD",
requestDescription: "Apple Pay test transaction",
trackingID: "1000000-1",
card: nil)
BeGateway.instance.payWithApplePay(requestBE: request, rootController: self) {
self.showSuccessAlert()
print("payment success without token")
} failureHandler: { error in
self.showFailureAlert(error: error)
print("---> error \(error)")
}
Apple Pay with TOKEN:
BeGateway.instance.payWithAppleByToken(token: token, rootController: self) {
self.showSuccessAlert()
print("payment success with token")
} failureHandler: { error in
self.showFailureAlert(error: error)
print("---> error \(error)")
}
You can pay with TOKEN
swift
BeGateway.instance.payByToken(
token: PAYMENTTOKEN,
card : CARD , rootController: self,
completionHandler: {
card in
print(card)
}, failureHandler: { error in
print(error)
})
Where PAYMENTTOKEN is a string value.
CARD - object of BeGatewayRequestCard instance.
Could be initiated with:
self.number = number - Card number
self.verificationValue = verificationValue - CVC Code
self.expYear = expYear - Year Expiration
self.expMonth = expMonth - Month Expiration
self.holder = holder - Card Holder Name
OR
self.cardToken = cardToken - For Card Token
If no previously saved card - empty object BeGatewayRequestCard() could be used.
### Other functions
#### Clear all saved `CARDS`
```swift
BeGateway.instance.removeAllCards()
You can customize card form view with BeGatewayOptions
in instance or create new object for BeGatewayOptions and set
let options = BeGatewayOptions();
BeGateway.instance.options = options
// title
BeGateway.instance.options?.title: String?
// font title
BeGateway.instance.options?.fontTitle: UIFont?
// color title
BeGateway.instance.options?.colorTitle: UIColor?
// title card number field
BeGateway.instance.options?.titleCardNumber: String = LocalizeString.localizeString(value:"Card number")
// hint card number field
BeGateway.instance.options?.hintCardNumber: String = LocalizeString.localizeString(value:"Card number")
// title card number field
BeGateway.instance.options?.cardNumber: String = LocalizeString.localizeString(value:"Card number")
// font for title card number
BeGateway.instance.options?.fontTitleCardNumber: UIFont?
// color for title card number
BeGateway.instance.options?.colorTitleCardNumber: UIColor?
// font for hint card number
BeGateway.instance.options?.fontHintCardNumber: UIFont?
// color for title card number
BeGateway.instance.options?.colorHintCardNumber: UIColor?
// font for text fields background color
BeGateway.instance.options?.textFieldBackgroundColor: UIColor?
// label expire date
BeGateway.instance.options?.titleExpiryDate: String = LocalizeString.localizeString(value:"Expiration date")
// hint expire date
BeGateway.instance.options?.hintExpiryDate: String = LocalizeString.localizeString(value:"Expiration date")
// title expire date
BeGateway.instance.options?.expiryDate: String = LocalizeString.localizeString(value:"Expiration date")
// font for title expire date
BeGateway.instance.options?.fontTitleExpiryDate: UIFont?
// color for title expire date
BeGateway.instance.options?.colorTitleExpiryDate: UIColor?
// hint for hint expire date
BeGateway.instance.options?.fontHintExpiryDate: UIFont?
// color for hint of expire date
BeGateway.instance.options?.colorHintExpiryDate: UIColor?
// label CVC
BeGateway.instance.options?.titleCVC: String = LocalizeString.localizeString(value:"CVC")
// hint CVC
BeGateway.instance.options?.hintCVC: String = LocalizeString.localizeString(value:"CVC")
// title CVC
BeGateway.instance.options?.cvc: String = LocalizeString.localizeString(value:"CVC")
// is secure mode for CVC field
BeGateway.instance.options?.isSecureCVC: Bool = false
// font fot title CVC
BeGateway.instance.options?.fontTitleCVC: UIFont?
// color for title CVC
BeGateway.instance.options?.colorTitleCVC: UIColor?
// font fot hint CVC
BeGateway.instance.options?.fontHintCVC: UIFont?
// color for hint CVC
BeGateway.instance.options?.colorHintCVC: UIColor?
// label for Card Holder Name
BeGateway.instance.options?.titleCardHolderName: String = LocalizeString.localizeString(value:"Name on card")
// hint for Card Holder Name
BeGateway.instance.options?.hintCardHolderName: String = LocalizeString.localizeString(value:"Name on card")
// title for Card Holder Name
BeGateway.instance.options?.cardHolderName: String = LocalizeString.localizeString(value:"Name on card")
// font title for Card Holder Name
BeGateway.instance.options?.fontTitleCardHolderName: UIFont?
// color title for for Card Holder Name
BeGateway.instance.options?.colorTitleCardHolderName: UIColor?
// font hint for Card Holder Name
BeGateway.instance.options?.fontHintCardHolderName: UIFont?
// color hint for Card Holder Name
BeGateway.instance.options?.colorHintCardHolderName: UIColor?
// button title
BeGateway.instance.options?.titleButton: String = LocalizeString.localizeString(value: "Pay")
// button text color
BeGateway.instance.options?.colorButton: UIColor?
// button font
BeGateway.instance.options?.fontButton: UIFont?
// button background color
BeGateway.instance.options?.backgroundColorButton: UIColor?
// toggle title
BeGateway.instance.options?.titleToggle: String = LocalizeString.localizeString(value:"Save card")
// error title
BeGateway.instance.options?.errorTitle: String = LocalizeString.localizeString(value:"Sorry, incorrect data")
// common text font
BeGateway.instance.options?.textFont: UIFont?
// common hint font
BeGateway.instance.options?.hintFont: UIFont?
// common text color
BeGateway.instance.options?.textColor: UIColor?
// common hint color
BeGateway.instance.options?.hintColor: UIColor?
// common background color
BeGateway.instance.options?.backgroundColor: UIColor = UIColor.clear
// turn on/off card number field
BeGateway.instance.options?.isToogleCardNumber: Bool = false
// turn on/off card exprire date field
BeGateway.instance.options?.isToogleExpiryDate: Bool = false
// turn on/off card CVC field
BeGateway.instance.options?.isToogleCVC: Bool = false
// turn on/off card holder name field
BeGateway.instance.options?.isToogleCardHolderName: Bool = false
// turn on/off card saved field
BeGateway.instance.options?.isToogleSaveCard: Bool = false
//You can track the click of the "Cancel" button on the payment screen
BeGateway.instance.options?.cancelButtonHandler
Example:
public override func viewWillAppear(_ animated: Bool) {
self.cancelButtonPressHandler()
}
private func cancelButtonPressHandler() {
let options = BeGateway.instance.options ?? BeGatewayOptions(clientPubKey: "")
options.cancelButtonHandler = {
// Your logic is here
print("The \"Cancel\" button was pressed")
}
}
You can change mode from test to production (by default, true)
BeGateway.instance.options?.test = false
You can change transaction type (by default, "payment")
BeGateway.instance.options?.transaction_type = "authorization"
You can get a payment status notification by setting notificationURL property
BeGateway.instance.options?.notificationURL = "https://yourdomain.com/payment/notification"
You can change language
BeGateway.instance.options?.language = "en"
You can change delay between responses
BeGateway.instance.options?.delayCheckingSec = 5
You can change max attempths when wainting response payment gateway
BeGateway.instance.options?.maxCheckingAttempts = 30
If you want use Encrypted mode for card
BeGateway.instance.options?.isEncryptedCreditCard = false
If you want to implement image capture you need to override method
onDetachFromCamera: ((_ onSelected: ((BeGatewayRequestCard?) -> Void)?) -> Void)?
beGateway SDK is released under the MIT license. See LICENSE for details.