You can find more information on how to use this library and sign up for a free Realex Payments sandbox account at https://developer.realexpayments.com
- iOS 9.0+
- Xcode 7.1.1+
- To integrate the Realex Payments iOS Library into your Xcode project using CocoaPods, specify it in your podfile:
pod 'RXPiOS', '~> 1.7.0'
- Then, run the following command:
$ pod install
If you prefer not to use a dependency manager, you can integrate the Realex Payments iOS Library into your project manually.
- Download the the latest release from GitHub:
https://github.com/realexpayments/rxp-ios/releases
- Drag and drop the folder 'RealexComponent' into Xcode to use the HPP part of the library.
- Run the following command:
$ pod install
- If you want to use the card data validation library, drag and drop the folder 'RealexRemote' into your Xcode project.
To instantiate an instance of the HPP manager do the following:
let hppManager = HPPManager()
The HPP Manager requires three server URLs.
-
Request Producer URL: utilizing one of the Realex HPP server SDKs; this URL creates the necessary request JSON for the component using the shared secret stored on the server side.
-
HPP URL: the location where the component sends the encoded request. The default for live transactions is https://pay.realexpayments.com/pay
-
Response Consumer URL: utilizing one of the Realex HPP server SDKs; takes the encoded response received back from HPP checks the validity of the hash and decodes the response.
hppManager.HPPRequestProducerURL = URL(string: "https://myserver.com/hppRequestProducer")
hppManager.HPPURL = URL(string: "https://pay.realexpayments.com/pay")
hppManager.HPPResponseConsumerURL = URL(string: "https://myserver.com/hppResponseConsumer")
Next you set the object which will act as the delegate for the HPPManager. The delegate should implement the HPPManagerDelegate protocol and so will receive the response from the HPP Manager:
hppManager.delegate = self
There are three possible outcomes from the HPP interaction:
-
It concluded successfully. This returns the decoded JSON from HPP, parsed as a native Dictionary of name / value pairs.
-
It failed with an error. This returns an object of the Error Class, you can access properties such as code and localizedDescription for more details on the error.
-
It was cancelled by the user.
The HPP Manager's delegate should implement the following three functions to receive back the result from the HPP Manager:
func HPPManagerCompletedWithResult(_ result: [String: String])
func HPPManagerFailedWithError(_ error: Error?)
func HPPManagerCancelled()
Using the presentViewInViewController() method the HPP Manager will process the given parameters, get the request from the server, send the encoded request to HPP and present the form received back:
hppManager.presentViewInViewController(self)
On the server-side using one of our server SDKs, setup your Response Consumer to take in the response JSON and create the HPP Response:
RealexHpp realexHpp = new RealexHpp("secret");
HppResponse hppResponse = realexHpp.responseFromJson(responseJson);
In case if your client-side code requires another type than [String: String]
when receiving HPPManagerCompletedWithResult
delegate, you need to set up the library differently
-
Change
HPPManagerDelegate
intoGenericHPPManagerDelegate
-
Change
HPPManager()
intoGenericHPPManager<HPPResponse>()
whereHPPResponse
is a custom defined struct or class. -
Change function signature
from
func HPPManagerCompletedWithResult(_ result: [String: String]) { ... }
into
func HPPManagerCompletedWithResult(_ result: HPPResponse) { ... }
Example:
final class ViewController: UIViewController, GenericHPPManagerDelegate {
func pay() {
let hppManager = GenericHPPManager<HPPResponse>()
hppManager.setGenericDelegate(self)
...
}
func HPPManagerCompletedWithResult(_ result: HPPResponse) { ... }
func HPPManagerFailedWithError(_ error: Error?) { ... }
func HPPManagerCancelled() { ... }
}
Note: By default, HPPManager is using [Stirng: String]
type.
You can also set whatever HPP properties you need to in the component, for example:
hppManager.merchantId = "realexsandbox"
hppManager.account = "internet"
hppManager.amount = "100"
hppManager.currency = "EUR"
These will be sent to the Request Producer URL, your server-side code must be setup to take in these values and pass them to the HPP server-side SDK for them to be included in the request.
Note, in addition to the predefined properties, you can add any amount of additional arbitrary properties as follows:
hppManager.supplementaryData["UNKNOWN_1"] = "Unknown value 1"
hppManager.supplementaryData["UNKNOWN_2"] = "Unknown value 2"
Also, in addition to predefined header values, you can add any amount of additional values as follows:
hppManager.additionalHeaders = ["custom-header-1": "test param 1",
"custom-header-2": "test param 2",
"custom-header-3": "test param 3"]
Realex Payments maintain separate endpoints for live and test transactions. You’ll need to override the HPP URL in the SDK to facilitate testing. Use the code below:
hppManager.HPPURL = URL(string: "https://pay.sandbox.realexpayments.com/pay")
See the LICENSE file.