|
| 1 | + |
| 2 | +# Cybersource Flex iOS - SDK |
| 3 | + |
| 4 | +This SDK allows mobile developers to provide credit card payment functionality within their iOS applications, without having to pass sensitive card data back to their application backend servers. For more information on including payments in your mobile application see our [InApp Payments Guide](TBD) |
| 5 | + |
| 6 | +## SDK Installation |
| 7 | + |
| 8 | +### CocoaPods |
| 9 | +``` |
| 10 | + pod 'flex-api-ios-sdk' |
| 11 | +``` |
| 12 | + |
| 13 | +### Manual Installation |
| 14 | + |
| 15 | +Include the ```flex-api-ios-sdk.framework``` in the application. In Xcode, select the main project file for the target. In the "General" section of the project's properties, scroll down to "Embedded Binaries", press the plus sign (+), and select the framework. |
| 16 | + |
| 17 | +Once included, make sure in “Build Settings” tab, in section “Search Paths”, the path to these frameworks are added correctly. |
| 18 | + |
| 19 | +## SDK Usage |
| 20 | + |
| 21 | +### Merchant details |
| 22 | +Please initialize environment to use and merchant details before creating capture context as below. To learn more on generating merchantKey and merchantSecret refer [Cybersource API Reference](https://developer.cybersource.com/api-reference-assets/index.html#authenticationSection) |
| 23 | +``` |
| 24 | + //use .sandbox to connect to sandbox |
| 25 | + let environment = Environment.production |
| 26 | +
|
| 27 | + let merchantId = "merchantId" |
| 28 | + let merchantKey = "key" |
| 29 | + let merchantSecret = "secret" |
| 30 | +``` |
| 31 | + |
| 32 | +### Create capture context |
| 33 | +Please refer sample application which demonstrates creation of Capture context |
| 34 | +[Sample App](TBD) |
| 35 | + |
| 36 | +```swift |
| 37 | + let captureContext = createCaptureContext() |
| 38 | +``` |
| 39 | +Create capture context uses HTTP Signature Authentication, please refer sample application to know how to create HTTP Signature and digest. For more information refer [HTTP Signature Authentication](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/authentication/GenerateHeader/httpSignatureAuthentication.html) |
| 40 | + |
| 41 | +### Initialize the SDK and create transient token using capture context |
| 42 | +```swift |
| 43 | + let service = FlexService() |
| 44 | + |
| 45 | + service.createTransientToken(from: captureContext, data: getPayload()) { (result) in |
| 46 | + DispatchQueue.main.async { [weak self] in |
| 47 | + switch result { |
| 48 | + case .success: |
| 49 | + //handle success case |
| 50 | + case let .failure(error): |
| 51 | + //handle error case |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +``` |
| 56 | +### Create payload |
| 57 | +```swift |
| 58 | + private func getPayload() -> [String: String] { |
| 59 | + var payload = [String: String]() |
| 60 | + payload["paymentInformation.card.number"] = "4111111111111111" |
| 61 | + payload["paymentInformation.card.securityCode"] = "123" |
| 62 | + payload["paymentInformation.card.expirationMonth"] = 12 |
| 63 | + payload["paymentInformation.card.expirationYear"] = 29 |
| 64 | + return payload |
| 65 | + } |
| 66 | +``` |
| 67 | +### Using the Accept Payment Token to Create a Transaction Request |
| 68 | +Your server constructs a transaction request using the [Cybersource API](https://developer.cybersource.com/api-reference-assets/index.html#payments_payments_process-a-payment_samplerequests-dropdown_payment-with-flex-token), placing the encrypted payment information that it received in previous step in the opaqueData element. |
| 69 | +```json |
| 70 | +{ |
| 71 | + "clientReferenceInformation": { |
| 72 | + "code": "TC50171_3" |
| 73 | + }, |
| 74 | + "orderInformation": { |
| 75 | + "amountDetails": { |
| 76 | + "totalAmount": "102.21", |
| 77 | + "currency": "USD" |
| 78 | + } |
| 79 | + }, |
| 80 | + "tokenInformation": { |
| 81 | + "transientTokenJwt": "eyJraWQiOiIwN0JwSE9abkhJM3c3UVAycmhNZkhuWE9XQlhwa1ZHTiIsImFsZyI6IlJTMjU2In0.eyJkYXRhIjp7ImV4cGlyYXRpb25ZZWFyIjoiMjAyMCIsIm51bWJlciI6IjQxMTExMVhYWFhYWDExMTEiLCJleHBpcmF0aW9uTW9udGgiOiIxMCIsInR5cGUiOiIwMDEifSwiaXNzIjoiRmxleC8wNyIsImV4cCI6MTU5MTc0NjAyNCwidHlwZSI6Im1mLTAuMTEuMCIsImlhdCI6MTU5MTc0NTEyNCwianRpIjoiMUMzWjdUTkpaVjI4OVM5MTdQM0JHSFM1T0ZQNFNBRERCUUtKMFFKMzMzOEhRR0MwWTg0QjVFRTAxREU4NEZDQiJ9.cfwzUMJf115K2T9-wE_A_k2jZptXlovls8-fKY0muO8YzGatE5fu9r6aC4q7n0YOvEU6G7XdH4ASG32mWnYu-kKlqN4IY_cquRJeUvV89ZPZ5WTttyrgVH17LSTE2EvwMawKNYnjh0lJwqYJ51cLnJiVlyqTdEAv3DJ3vInXP1YeQjLX5_vF-OWEuZfJxahHfUdsjeGhGaaOGVMUZJSkzpTu9zDLTvpb1px3WGGPu8FcHoxrcCGGpcKk456AZgYMBSHNjr-pPkRr3Dnd7XgNF6shfzIPbcXeWDYPTpS4PNY8ZsWKx8nFQIeROMWCSxIZOmu3Wt71KN9iK6DfOPro7w" |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | +## Sample Application |
| 86 | +We have a sample application which demonstrates the SDK usage: |
| 87 | +[Sample App](TBD) |
0 commit comments