User Preference

The User Preference API allows merchants to retrieve information on customers' payment preference, such as recently used payment channels, recent transaction information, and locale.

📘

API Method

PGW SDK API Interface

🚧

References

SDK Payment Classes
SDK Payment Enums


1. Generate Payment Token

To prepare a payment token request, refer to the required parameters below.

📘

Payment Token API

Refer to: Payment Token API

{
    "merchantID": "JT04",
    "invoiceNo": "1595219400",
    "description": "2 days 1 night hotel room",
    "amount": 10.0,
    "currencyCode": "THB",
    "nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
    "paymentChannel": ["ALL"],
    "uiParams": {
          "userInfo": {
              "name": "DavidBilly",
              "email": "[email protected]",
              "currencyCode": "SGD",
              "countryCode": "SG",
              "mobileNo": "88888888",
              "mobileNoPrefix": "65"
          }
      } 
}

2. Receive Payment Token Response

To receive a payment token response, refer to the sample payment token response below. The response will contain the payment token ID which must be passed to the merchant application.

String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
val paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';

3. Prepare User Preference Request

To prepare a user preference request, refer to the parameters below.

📘

Request API Parameters

Refer to: User Preference Request API Parameters

UserPreferenceRequest userPreferenceRequest = new UserPreferenceRequest(paymentToken);
val userPreferenceRequest = UserPreferenceRequest(paymentToken)
UserPreferenceRequest *userPreferenceRequest = [[UserPreferenceRequest alloc] initWithPaymentToken: paymentToken];
let userPreferenceRequest: UserPreferenceRequest = UserPreferenceRequest(paymentToken: paymentToken)
Map<String, dynamic> userPreferenceRequest = {
   'paymentToken': paymentToken
};
let userPreferenceRequest = {
    'paymentToken': paymentToken
};

4. Retrieve User Preference Response

To retrieve a user preference response, refer to the parameters below.

📘

Response API Parameters

Refer to: User Preference Response API Parameters

PGWSDK.getInstance().userPreference(userPreferenceRequest, new APIResponseCallback<UserPreferenceResponse>() {
  
     @Override
     public void onResponse(UserPreferenceResponse response) { 
       
         if (response.getResponseCode().equals(APIResponseCode.APISuccess)) {
           
             //Read user preference response. 
         } else {
           
             //Get error response and display error.
         }
     }
 
     @Override
     public void onFailure(Throwable error) {
       
         //Get error response and display error.
     }
});
PGWSDK.getInstance().userPreference(userPreferenceRequest, object : APIResponseCallback<UserPreferenceResponse> {
 
      override fun onResponse(response: UserPreferenceResponse) {
 
            if (response.responseCode == APIResponseCode.APISuccess) {
 
                  //Read user preference response.
            } else {
 
                  //Get error response and display error.
            }
      }
 
      override fun onFailure(error: Throwable) {
 
            //Get error response and display error.
      }
})
[[PGWSDK shared] userPreferenceWithUserPreferenceRequest: userPreferenceRequest response: ^(UserPreferenceResponse * _Nonnull response) {
  
     if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) { 
       
          //Read user preference response.
     } else { 
       
         //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) { 
  
     //Get error response and display error.
}];
PGWSDK.shared.userPreference(userPreferenceRequest: userPreferenceRequest, { (response: UserPreferenceResponse) in
 
     if response.responseCode == APIResponseCode.APISuccess {
       
          //Read user preference response.
     } else {
       
          //Get error response and display error.
     }
}) { (error: NSError) in
    
     //Get error response and display error.
}
PGWSDK().userPreference(userPreferenceRequest, (response) {
 
   if (response['responseCode'] == APIResponseCode.apiSuccess) {
 
      //Read user preference response.
   } else {
 
      //Get error response and display error.
   }
}, (error) {
 
   //Get error response and display error.
});
await RTNPGW.userPreference(JSON.stringify(userPreferenceRequest)).then((response: string) => {
 
    let userPreferenceResponse = JSON.parse(response);
 
    if (userPreferenceResponse?.responseCode == APIResponseCode.apiSuccess) {
 
        //Read user preference response.
    } else {
 
        //Get error response and display error
    }
}).catch ((error: Error) => {
 
    //Get error response and display error
});

Full Sample Code

The following sample code demonstrates requests and parameters for each step of the process.

//Step 1: Generate payment token.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct user preference request.
UserPreferenceRequest userPreferenceRequest = new UserPreferenceRequest(paymentToken);
 
//Step 3: Retrieve user preference response.
PGWSDK.getInstance().userPreference(userPreferenceRequest, new APIResponseCallback<UserPreferenceResponse>() {
  
     @Override
     public void onResponse(UserPreferenceResponse response) {
       
         if (response.getResponseCode().equals(APIResponseCode.APISuccess)) {
           
             //Read user preference response. 
         } else {
           
             //Get error response and display error.
         }
     }
 
     @Override
     public void onFailure(Throwable error) {
       
         //Get error response and display error.
     }
});
//Step 1: Generate payment token.
val paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
 
//Step 2: Construct user preference request.
val userPreferenceRequest = UserPreferenceRequest(paymentToken)
 
//Step 3: Retrieve user preference response.
PGWSDK.getInstance().userPreference(userPreferenceRequest, object : APIResponseCallback<UserPreferenceResponse> {
 
      override fun onResponse(response: UserPreferenceResponse) {
 
            if (response.responseCode == APIResponseCode.APISuccess) {
 
                  //Read user preference response.
            } else {
 
                  //Get error response and display error.
            }
      }
 
      override fun onFailure(error: Throwable) {
 
            //Get error response and display error.
      }
})
//Step 1: Generate payment token.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct user preference request.
UserPreferenceRequest *userPreferenceRequest = [[UserPreferenceRequest alloc] initWithPaymentToken: paymentToken];
     
//Step 3: Retrieve user preference response.
[[PGWSDK shared] userPreferenceWithUserPreferenceRequest: userPreferenceRequest response: ^(UserPreferenceResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
       
          //Read user preference response.
     } else {
       
         //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) { 
  
     //Get error response and display error.
}];
//Step 1: Generate payment token.
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
 
//Step 2: Construct user preference request.
let userPreferenceRequest: UserPreferenceRequest = UserPreferenceRequest(paymentToken: paymentToken)
         
//Step 3: Retrieve user preference response.
PGWSDK.shared.userPreference(userPreferenceRequest: userPreferenceRequest, { (response: UserPreferenceResponse) in
 
     if response.responseCode == APIResponseCode.APISuccess {
       
          //Read user preference response.
     } else {
       
          //Get error response and display error.
     }
}) { (error: NSError) in
    
     //Get error response and display error.
}
//Step 1: Generate payment token.
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
 
//Step 2: Construct user preference request.
Map<String, dynamic> userPreferenceRequest = {
   'paymentToken': paymentToken
};
 
//Step 3: Retrieve user preference response.
PGWSDK().userPreference(userPreferenceRequest, (response) {
 
   if (response['responseCode'] == APIResponseCode.apiSuccess) {
 
      //Read user preference response.
   } else {
 
      //Get error response and display error.
   }
}, (error) {
 
   //Get error response and display error.
});
//Step 1: Generate payment token.
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
 
//Step 2: Construct user preference request.
let userPreferenceRequest = {
    'paymentToken': paymentToken
};
 
//Step 3: Retrieve user preference response.
await RTNPGW.userPreference(JSON.stringify(userPreferenceRequest)).then((response: string) => {
 
    let userPreferenceResponse = JSON.parse(response);
 
    if (userPreferenceResponse?.responseCode == APIResponseCode.apiSuccess) {
 
        //Read user preference response.
    } else {
 
        //Get error response and display error
    }
}).catch ((error: Error) => {
 
    //Get error response and display error
});