# iOS SDK

## IOS SDK for NeoX Payment Gateway

**Use**

<pre class="language-swift"><code class="lang-swift"><strong>import SwiftUI 
</strong>import NeoPaySDK

struct Payment: View {
    @Environment(\.presentationMode) var presentationMode: Binding&#x3C;PresentationMode>
 
    var method: String
    @Binding var showingAlert:Bool
    @Binding var alert:String
    var amount: Int64

    var body: some View {
      
        let request = NeoRequest(
            neo_MerchantCode: "HUYEN1",
            neo_PaymentMethod: self.method,
            neo_Amount: amount,
            neo_MerchantTxnID:"T" + String(Int.random(in: 0..&#x3C;9999)),
            neo_OrderID: "DH" + String(Int(Date().timeIntervalSince1970)),
            neo_OrderInfo:"123",
            secureHash: "123456", 
            neo_ENV: .uat
          
        )
        let customHeader = NeoCustomHeader() 
        let customButton = NeoCustomButton(
//            title: "Thanh toán",
//            textColor: "#fff",
//            background: "blue"
        )
        
        let params = NeoParams(request: request,  backHandler: {
            self.presentationMode.wrappedValue.dismiss()
        }, customHeader: customHeader,customButton: customButton) { success, failure in
            if let success = success {
                print("success  \(success)")
                
            }
            if let failure = failure {
                print("failure  \(failure)")
            }
                
        }
      
        VStack{
            NeoSDKView(params:params)
        }.hiddenNavigationBarStyle()
    }
   
}



</code></pre>

{% tabs %}
{% tab title="Swift" %}

```swift
import SwiftUI 
import NeoPaySDK

struct Payment: View {
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
 
    var method: String
    @Binding var showingAlert:Bool
    @Binding var alert:String
    var amount: Int64

    var body: some View {
      
        let request = NeoRequest(
            neo_MerchantCode: "HUYEN1",
            neo_PaymentMethod: self.method,
            neo_Amount: amount,
            neo_MerchantTxnID:"T" + String(Int.random(in: 0..<9999)),
            neo_OrderID: "DH" + String(Int(Date().timeIntervalSince1970)),
            neo_OrderInfo:"123",
            secureHash: "123456", 
            neo_ENV: .uat
          
        )
        let customHeader = NeoCustomHeader() 
        let customButton = NeoCustomButton(
//            title: "Thanh toán",
//            textColor: "#fff",
//            background: "blue"
        )
        
        let params = NeoParams(request: request,  backHandler: {
            self.presentationMode.wrappedValue.dismiss()
        }, customHeader: customHeader,customButton: customButton) { success, failure in
            if let success = success {
                print("success  \(success)")
                
            }
            if let failure = failure {
                print("failure  \(failure)")
            }
                
        }
      
        VStack{
            NeoSDKView(params:params)
        }.hiddenNavigationBarStyle()
    }
   
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
//  ViewController.m
#import "ViewController.h"
#import "DemoObjectiveC-Swift.h"

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@"The code runs through here!");
    // Do any additional setup after loading the view.
}

- (IBAction)buttonTapped:(id)sender {
    NSInteger *amount = 10000;
    NSTimeInterval timeInSeconds = [[NSDate date] timeIntervalSince1970];
    NSString *timeInSecondsString = [NSString stringWithFormat:@"%d",timeInSeconds];
    NSString *orderID = [@"DH"  stringByAppendingString:timeInSecondsString];
    NSLog(orderID);
    [self displayNeoPaySDKWithAmount:amount orderID:orderID];
   
}
@end

```

{% endtab %}
{% endtabs %}

**displayNeoPaySDKWithAmount (function in SDKView file)**

```swift
// SDKView
import Foundation
import NeoPaySDK
import SwiftUI


@objc extension ViewController {
    func displayNeoPaySDK(amount:Int64 = 0,orderID:String){
       
         let host = UIHostingController(rootView: SDKView(amount:amount,orderID: orderID))
        host.modalPresentationStyle = .fullScreen
        self.present(host, animated: true)
        
    }
}

struct SDKView: View{
    public init(amount :Int64 = 0,orderID:String) {
//          print("Vo day may lan")
        self.amount = amount
        self.orderID = orderID
    }
    var amount:Int64 = 0
    var orderID:String = ""
    @Environment(\.dismiss) var dismiss
    @State private var showingAlert = false
    @State private var alert = ""
    
    var body:some View {
        let request = NeoRequest(
            neo_MerchantCode: "HUYEN1",
            neo_PaymentMethod: "",
            neo_Amount: self.amount,
            neo_MerchantTxnID:"T" + String(Int.random(in: 0..<9999)),
            neo_OrderID:  self.orderID ?? "DH" + String(Int(Date().timeIntervalSince1970)),
            neo_OrderInfo:"123",
            secureHash: "123456",
            neo_ENV: .uat
        )
        
        let params = NeoParams(request: request,  backHandler: {
            self.dismiss()
        }) { success, failure in
            if let success = success {
                print("success ne \(success)")
                self.showingAlert = true
                self.alert = "Thanh toán thành công"
//                self.dismiss()
                
            }
            if let failure = failure {
                print("failure ne \(failure)")
                self.showingAlert = true
                self.alert = "Thanh toán thất bại"
            }
                
        }
        
        VStack{
            if self.showingAlert == false && self.alert == ""{
                NeoSDKView(params:params)
            }
            else{
                Button(action: {
                               
                            }) {
                                Text("")
                            }.alert(isPresented: $showingAlert) {
                    Alert(title: Text("Thông báo"), message: Text(alert), dismissButton: .destructive(Text("Đồng ý")) {
                        self.dismiss()
                    })
                }
            }
           
        }
          
    }
}

```

#### Methods <a href="#sdfsd" id="sdfsd"></a>

<table><thead><tr><th width="188">Method</th><th>Description</th></tr></thead><tbody><tr><td>init</td><td>Initialize the necessary configurations for the SDK and UI</td></tr></tbody></table>

NeoSDKView **(**&#x70;arams:NeoParam&#x73;**)**

NeoParams(request,backHandler,customHeader)

<table><thead><tr><th width="170">Parammetter</th><th width="189">Data Type</th><th>Description</th></tr></thead><tbody><tr><td>request</td><td><a href="#neorequest">NeoRequest</a></td><td>Input params </td></tr><tr><td>customHeader</td><td><a href="#neocustomheader">NeoCustomHeader</a></td><td>Allows header customization</td></tr><tr><td>customButton</td><td><a href="#neocustombutton">NeoCustomButton</a></td><td>Allows Button customization</td></tr></tbody></table>

## NeoRequest&#x20;

<table><thead><tr><th width="217">Parammetter</th><th width="111">Data Type</th><th width="133">Default Value</th><th>Description</th></tr></thead><tbody><tr><td>neo_MerchantCode</td><td>String</td><td></td><td>Merchant code is provided by NeoX</td></tr><tr><td>neo_Currency</td><td>String</td><td>VND</td><td>Transaction currency, VND as default</td></tr><tr><td>neo_Locale</td><td>String</td><td>vi</td><td>Language will display on the checkout page. Support: “vi”, “en”.</td></tr><tr><td>neo_Version</td><td>string</td><td>1</td><td>Payment gateway version, “1” as default</td></tr><tr><td>neo_PaymentMethod</td><td>String</td><td>["WALLET", "ATM", "CC", "QR"]</td><td>Allows to choose to display direct or list payment channels. If this field is not transmitted, all channels will be displayed.</td></tr><tr><td>neo_Amount</td><td>number</td><td></td><td>Payment amount</td></tr><tr><td>neo_MerchantTxnID</td><td>String</td><td></td><td>Unique - Transaction ID is provided by merchant</td></tr><tr><td>neo_OrderID</td><td>String</td><td></td><td>Oder ID</td></tr><tr><td>neo_ENV</td><td>Enum</td><td>[dev,uat,prod]</td><td>Environment</td></tr></tbody></table>

### **NeoCustomHeader**

<table><thead><tr><th>Parammetter</th><th width="173.33333333333331">Data Type</th><th>Default Value</th></tr></thead><tbody><tr><td>title</td><td>Font</td><td>Thanh toán</td></tr><tr><td>textColor</td><td>Color</td><td>Color.black</td></tr><tr><td>background</td><td>Color</td><td>Color.white</td></tr><tr><td>font</td><td>Font</td><td>Font.system(size:20, design: .default)</td></tr><tr><td>fontWeight</td><td>Font.Weight</td><td>Font.Weight.bold</td></tr><tr><td>imgLeft</td><td>AnyView</td><td>AnyView(Image(systemName: "chevron.backward").padding(sides: [.left], value: 16))</td></tr></tbody></table>

### NeoCustomButton

| Parammetter  | Data Type | Default Value |
| ------------ | --------- | ------------- |
| title        | String    | Thanh toán    |
| textColor    | String    | #000          |
| background   | String    | #fed07f       |
| fontSize     | String    | 14px          |
| fontWeight   | String    | bold          |
| borderRadius | String    | 25px          |

**Callback**

<table><thead><tr><th width="191">Event</th><th>Description</th></tr></thead><tbody><tr><td>onSuccess</td><td>The event occurs when payment is successful.</td></tr><tr><td>onFailure</td><td>The event occurs when payment fails.</td></tr></tbody></table>

**Callback data from onSuccess and onFailure**

<table><thead><tr><th>Parameter</th><th width="147.33333333333331">Data Type</th><th>Description</th></tr></thead><tbody><tr><td>neo_MerchantCode</td><td>string</td><td>Merchant code is provided by NeoX</td></tr><tr><td>neo_Currency</td><td>string</td><td>Transaction currency, VND as default</td></tr><tr><td>neo_Locale</td><td>string</td><td>Language will display on the checkout page. Support: “vi”, “en”.</td></tr><tr><td>neo_Version</td><td>string</td><td>Payment gateway version, “1” as default</td></tr><tr><td>neo_Command</td><td>string</td><td>“PAY” as default</td></tr><tr><td>neo_Amount</td><td>string</td><td>Payment amount</td></tr><tr><td>neo_MerchantTxnID</td><td>string</td><td>Unique - Transaction ID is provided by merchant</td></tr><tr><td>neo_OrderID</td><td>string</td><td>Oder ID</td></tr><tr><td>neo_OrderInfo</td><td>string</td><td>Oder Information</td></tr><tr><td>neo_TransactionID</td><td>string</td><td>Unique - Transaction ID is generated by the NeoX system,  for reconciling.</td></tr><tr><td>neo_ResponseCode</td><td>string</td><td>The error code is returned by NeoX, indicates the transaction result.</td></tr><tr><td>neo_ResponseMsg</td><td>string</td><td>Error description.</td></tr><tr><td>neo_CustomerID</td><td>string</td><td>The customer ID on the merchant system.</td></tr><tr><td>neo_ResponseData</td><td>string</td><td>The data response of customer's payment.</td></tr><tr><td>neo_SecureHash</td><td>string</td><td>Use SHA256 to hash the above parameters (sort the key by Alphabet order) + Secret Key (will be provided by NeoX after actual integration)</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neox.vn/docs/global/payment-gateway/integrations/hosted-checkout/ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
