iOS Native SDK - Connect(V2)
#
1. OverviewIntegrate PortOne iOS Native SDK to enable secure and efficient payment processing in your iOS application. This guide will help you set up the SDK and start accepting payments seamlessly.
#
2. Video TutorialFor a comprehensive guide on integrating the PortOne iOS SDK and using the payment method flow, refer to the following video tutorials:
- iOS Integration: Watch Tutorial
- Accessing PortOne Checkout: Watch Tutorial
#
3. Sample AppExplore the sample application for integration examples on GitHub.
#
4. PrerequisitesBefore starting the integration, ensure you have:
- PortOne Account: Create an account on PortOne to access their services.
- API Keys: Obtain your API keys (client key and secret key) from the PortOne portal under Settings -> API tab.
- Enable Payment Channels: Customize and enable the payment channels and methods according to your business requirements.
- iOS Application: Prepare an iOS application where you will integrate the PortOne SDK.
- Download the Framework: Get the latest framework from here.
#
5. Integration Steps#
5.1. Embed the Framework in ProjectAdd Framework:
- Download the
.xcframework
from the version folder. - Drag and drop it into your Xcode project.
- Go to
General
->Frameworks, Libraries, and Embedded Content
. - Set the framework to
Embed & Sign
.
- Download the
#
5.2. Enable Deep Linking in iOSConfigure URL Schemes:
Open your project settings and navigate to
Info
.Add URL schemes and identifiers under
URL Types
ininfo.plist
:
Add URL Schemes for Other Apps:
Support HTTP Connections:
Add the following to
info.plist
:
#
5.3. Obtain JWT TokenGenerate JWT Token:
- Implement server-side logic to generate a JWT token using the
portoneKey
. - Retrieve the JWT token in your iOS app and store it securely.
- Implement server-side logic to generate a JWT token using the
#
5.4. Generate Signature HashCreate Signature Hash:
- Use HmacSHA256 to generate a signature hash for the payload.
#
5.5. Initialize and Authorize SDKImport SDK:
Initialize Checkout:
Implement Delegate Methods:
#
Different Payment MethodsHere's the aligned and organized version of your code and explanations for initializing new card payments, handling saved cards, and processing wallet transactions.
#
1. Initialize the New Card PaymentTo start a new card payment, you need to initialize the payment with the required details and configuration:
#
Prepare Configuration for TransactionCreate and configure the transaction request details:
#
Handle Success and Failure CasesImplement the CheckoutDelegate
to handle transaction responses:
#
Sample Success and Failure CallbacksSuccess:
Failure:
#
Sample JWT TokenEnsure the JWT token is properly formatted and used for authentication:
#
2. Fetch Saved CardsTo fetch saved credit card details, follow these steps:
#
a. Generate OTPCall the getOTP
method to send an OTP to the user mobile number:
#
b. Fetch Saved CardsOnce the OTP is received, use it along with the mobile number to fetch saved cards:
#
Sample ResponsesSuccess Response:
Failure Response:
#
c. Process Payment with Saved CardInitialize the payment with the details of a saved card:
#
3. Wallet TransactionsTo initiate wallet payments, use the initiatePayment
method:
#
a. Handle Responses from DelegateImplement the CheckoutDelegate
to handle transaction responses:
Sample Response
#
4. Direct Bank Transfer#
Fetch Direct Bank Transfer DetailsTo fetch the Direct Bank Transfer details:
#
Process Direct Bank Transfer PaymentPrepare the payload with DirectBankTransferDetails
and initiate the payment:
#
5. Instalments#
Fetch Bank List for InstalmentsBank list body params:
amount
(Double)environment
(String)portoneKey
(String)isMerchantSponsored
(Boolean)paymentMethod
(String)overrideDefault
(Boolean)currency
(String)
#
Process Instalment PaymentPrepare the payload with BankDetails
and initiate the payment:
#
6. Fetch Available Payment Methods#
7. Merchant Centric Card Vault#
Add Customer CardCardData Example:
#
Delete Customer CardDeleteCardDataObject Example:
#
Fetch All Customer CardsHere's a detailed guide for implementing failover routing, and pre-authorization and capture payment functionalities using Swift.
#
8. Failover Routing#
1. Enable Failover Routing in Payment RequestTo enable failover routing, set the following parameters in your payment payload:
isRoutingEnabled
totrue
routingParams
withtype
set to"failover"
and therouteRef
from the merchant portal
Here's how to set these parameters and initiate the payment:
#
2. Fetch List of RoutesTo fetch the list of routes created in the merchant portal, use the fetchRoutes
method:
#
9. Pre-Authorization and Capture Payment#
1. Implement Pre-AuthorizationTo set up a pre-authorization, adjust the transactionType
in your payload:
#
2. Capture PaymentTo capture a payment, use the captureTransactionAPI
method with the necessary parameters:
#
Payload StructureTo successfully create a payment request, the payload must include various parameters organized as follows:
1. Web Checkout Request Parameters:
Parameter | Data Type | Description |
---|---|---|
portOneKey | String | Mandatory key for authentication |
merchantDetails | MerchantDetails | Details about the merchant |
merchantOrderId | String | Mandatory unique order identifier |
signatureHash | String | Mandatory security hash for the request |
amount | Double | Mandatory total amount for the transaction |
currency | String | Mandatory currency code (e.g., USD) |
countryCode | String | Mandatory country code (e.g., US) |
billingDetails | BillingDetails | Optional billing information |
shippingDetails | ShippingDetails | Optional shipping information |
orderDetails | [OrderDetail] | Optional array of order details |
successUrl | String | Mandatory URL to redirect on successful payment |
failureUrl | String | Mandatory URL to redirect on failed payment |
expiryHours | Int | Mandatory expiry time for the transaction in hours |
source | String | Mandatory source of the payment request |
description | String | Optional description of the transaction |
showShippingDetails | Boolean | Optional flag to show shipping details |
showBackButton | Boolean | Optional flag to show a back button |
defaultGuestCheckout | Boolean | Optional flag for default guest checkout |
isCheckoutEmbed | Boolean | Optional flag if the checkout is embedded |
redirectUrl | String | Mandatory URL to redirect after checkout |
environment | String | Mandatory environment type (sandbox or live) |
bankDetails | BankDetails | Optional bank details for payment |
directBankTransfer | DirectBankTransferDetails | Optional direct bank transfer details |
2. MerchantDetails:
Parameter | Data Type | Description |
---|---|---|
name | String | Optional merchant name |
logo | String | Optional URL to merchant's logo |
backUrl | String | Optional URL to redirect back |
promoCode | String | Optional promotional code |
promoDiscount | Int | Optional promotional discount |
shippingCharges | Double | Optional shipping charges |
3. ShippingDetails:
Parameter | Data Type | Description |
---|---|---|
shippingName | String | Optional shipping recipient name |
shippingEmail | String | Optional shipping recipient email |
shippingPhone | String | Optional shipping recipient phone |
shippingAddress | Address | Optional shipping address |
4. BillingDetails:
Parameter | Data Type | Description |
---|---|---|
billingName | String | Optional billing name |
billingEmail | String | Optional billing email |
billingPhone | String | Optional billing phone |
billingAddress | Address | Optional billing address |
5. Address:
Parameter | Data Type | Description |
---|---|---|
city | String | Optional city |
countryCode | String | Optional country code |
locale | String | Optional locale |
line1 | String | Optional address line 1 |
line2 | String | Optional address line 2 |
postalCode | String | Optional postal code |
state | String | Optional state |
6. DirectBankTransferDetails:
Parameter | Data Type | Description |
---|---|---|
customerName | String | Mandatory customer name |
transactionTime | String | Mandatory transaction time |
amountPaid | Double | Mandatory amount paid |
7. BankDetails:
Parameter | Data Type | Description |
---|---|---|
bankName | String | Mandatory bank name |
bankCode | String | Mandatory bank code |
isMerchantSponsored | Bool | Mandatory flag for merchant-sponsored bank |
instalmentPeriod | InstalmentPeriod | Mandatory instalment details |
8. InstalmentPeriod:
Parameter | Data Type | Description |
---|---|---|
month | Int | Mandatory number of months |
interest | Double | Mandatory interest rate |
9. OrderDetail:
Parameter | Data Type | Description |
---|---|---|
id | String | Optional order ID |
price | Double | Optional price of the item |
name | String | Optional name of the item |
quantity | Int | Optional quantity |
image | String | Optional image URL |
#
Probable Errors#
Pass the viewController which is embedded in navigation controller to checkout delegate- If the passed view controller does not have any navigation by default, the top view controller will be taken from the application's shared windows.
#
INVALID_UNAUTHORIZED_JWT_TOKEN_ERROR- Check whether PortOne Key and the Secret Key are from the same account.
- Check whether the Secret Key has not been modified.
- Check whether the
Bearer
keyword is added before the generated token with a space. Format:Bearer $jwtToken
. - Verify if the expiration time is greater than the current time.
#
INVALID_UNAUTHORISED_TRANSACTION_SIGNATURE_ERROR- Check whether all parameters match with the payload/request.
- Check whether the portone key matches with the payload and the account.
#
INVALID_UNAUTHORISED_TRANSACTION_IAMPORTKEY_ERROR- Check whether the portone key matches with the payload and the account.
#
INVALID_PAYMENT_CHANNEL- Make sure the payment channels and payment methods added in the payload are enabled from the PortOne portal.
#
INVALID_ENVIRONMENT- Ensure you have specified the environment as either
sandbox
orlive
.
#
Summation of order value, tax, duties, shipping, and discount is equal to amount- If items are provided, verify that the values match the total amount:
sum(items price * items quantity) + shipping charge - discount = amount
. - Mandatory parameters in payload:
- price
- promo_discount (0 is acceptable)
- shipping_charges (0 is acceptable)