Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobilesdk #106

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
---
== iOS SDK

For downloading MPSDK and basic setup, refer to <<MobilePaymentSDK_iOS_BasicSetup, Basic Setup>>.

[#MobilePaymentSDK_iOS_Introduction]
Mobile paymentSDK is divided into a core module and several secondary modules, one for each payment method.

With this modular approach, you can pick and choose what you need: a few payment methods (or even just one) or the full selection.

Below, we will briefly go through the basic requirements/dependencies, but also code examples for client initialization and processing the payment response on your end.

[#MobilePaymentSDK_iOS_System_Requirements]
The minimal requirement deployment target is 11.0.

[#MobilePaymentSDK_iOS_BasicSetup]
---
=== Basic Setup
Expand Down Expand Up @@ -128,4 +140,85 @@ image:images/07-01-basic-setup-and-integraton/iOS/target-properties.png[Custom i
- *Key:* 'No debugging check'
- *Value* - $(SDKPay_NO_DEBUG_CHECK)

image:images/07-01-basic-setup-and-integraton/iOS/user-defined-settings.png[User-Defined Settings]
image:images/07-01-basic-setup-and-integraton/iOS/user-defined-settings.png[User-Defined Settings]


[#MobilePaymentSDK_iOS_Client_Initialization]
==== Client Intialization
When creating a payment object, don't forget to initialize the client first (for example in AppDelegate class):

[source,swift]
----

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

do {
var hostname:String = "api-test.getneteurope.com"
var parameters: SDKPayECClientParameters = SDKPayECClientParameters()
parameters.timeoutInterval = 0 //default 30s
self.client = try SDKPayECClient.init(hostname: hostname, parameters: parameters)
} catch {
print(error);
}

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

if let client = self.client {
let openURL = client.open(url)
return openURL
}
return true
}

----

[#MobilePaymentSDK_iOS_Processing_the_response]
==== Response processing
This is example code for processing the response (to see the result of the transaction), after the payment goes through:
[source,swift]
----
@IBAction func onPayAction(_ sender: UIButton!) {

var payment = self.createCardPayment()
self.animatedCardfield.cardPayment = payment

(UIApplication.shared.delegate as! AppDelegate).client?.make(payment, withCompletion: { [weak self] (response: SDKPayECPaymentResponse?,error: Error?) in
guard let self = self else { return }

let alertMessage = error != nil ? error!.localizedDescription : "Success"
})
}

----

[#obilePaymentSDK_iOS_PaymentResponse_Object_Reference]
The `SDKPayECPaymentResponse` object is inherited from the SDKPayECPayment object. If the response was succesfull SDKPayECPaymentResponse object contains actual payment response parameters:

- **`transactionState`**: `SDKPayECTransactionState` - Returns a transaction state
- **`transactionIdentifier`**: `String` - A unique identifier assigned for every Transaction.
- **`statusMessage`**: `String` - All status messaeges composed into one string
- **`providerTransactionReferenceId`**: `String` - A unique identifier assigned for every provider transaction.

[#MobilePaymentSDK_iOS_BasicSetup_Localization]
==== Localization

The locale can be realized by a few way steps:

[arabic]
. **`locale` parameter in the payment request is set** - selected locale is sent to the backend and SDK UI is set to specified language,
. **`locale` parameter in the payment request is not set** - Mobile Payment SDK reads the list of customer localization settings in the mobile device and searches in order of this list for the first available localization supported by SDK. If localization is suitabsetupsset ups it for UI localization. If not the default English SDK localization is set up.


This example shows the first option: the backend `locale`:
[source,swift]
----
let payment = SDKPayECCardPayment()
payment.amount = 1.00
payment.currency = "EUR"
payment.transactionType = .purchase

payment.locale = "DE"
----
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,84 @@ recurring type. Check the API documentation <<GeneralPlatformFeatures_Transactio

//-

[#MobilePaymentSDK_iOS_CreditCard_toeknized_payment]
=== Tokenized Credit Card Payment
---
On a basic level, tokenized payments have two phases:

[arabic]
. The first request, which must include:
* `transactionType` parameter set to
`.tokenize`,
. The follow-up requests, which must include:
* `token` parameter set to
`value od token from the initial request,

So in order to create a toeknized payment, you need to:

[arabic]
. Send a initial request with the appropriate transactionType type,
. Save the values of `cardToken` parameter generated in this first payment,
. Reference these values in the follow-up request, then send it in token parameter.

This is a code example for a first tokenized Credit Card payment:
[source,swift]
----
// First payment


let payment = SDKPayECCardPayment()
payment.merchantAccountID = merchantAccountID
payment.requestID = requestID
payment.amount = NSDecimalNumber(mantissa: 199, exponent: -2, isNegative: NO)
payment.currency = "EUR"
payment.transactionType = .tokenize
payment.signature = signature

var tokenId: String?

self.client?.make(payment, withCompletion:{(response: SDKPayECPaymentResponse?,error: Error?) in
// for each failure error object is provided;
if let error = error {
return
}
self.handleResponse(response)
})

// Handle first result
func handleReponse(_ response: SDKPayECPaymentResponse?) {
guard let response = response else { return }
self.tokenId = response.cardToken.tokenID
}

// Second payment using token

let payment = SDKPayECCardPayment()
payment.merchantAccountID = merchantAccountID
payment.requestID = requestID
payment.parentTransactionID = self.parentTransactionID
payment.amount = NSDecimalNumber(mantissa: 199, exponent: -2, isNegative: NO)
payment.currency = "EUR"
payment.transactionType = .purchase
payment.signature = signature

let token = SDKPayECCardToken()
token.tokenId = tokenId
payment.token = token


self.client?.make(payment, withCompletion:{(response: SDKPayECPaymentResponse?,error: Error?) in
// for each failure error object is provided;
if let error = error {
return
}
self.handleResponse(response)
})
```
----

//-

[#MobilePaymentSDK_iOS_CreditCard_recurring_payment]
=== Recurring Credit Card Payment
---
Expand Down