Payment Notification
The Payment Notification API allows merchants to share payment results with customers through customers' preferred channels (e.g., email, Facebook, WhatsApp, WeChat, etc.)
Refer to the links below for parameters and code samples for each step:
- Generate Payment Token
- Prepare Payment Notification Request
- Retrieve Payment Notification Response
- Full Sample Code
API Method
References
1. Generate Payment Token
To prepare a payment token request, refer to the required parameters below.
{
"merchantID": "JT04",
"invoiceNo": "1595219400",
"description": "2 days 1 night hotel room",
"amount": 10.0,
"currencyCode": "THB",
"nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
"paymentChannel": ["ALL"]
}
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';
Payment Token API
Refer to: Payment Token API
3. Construct Payment Notification Request
To prepare a payment notification request, refer to the parameters below.
Request API Parameters
PaymentNotificationRequest paymentNotificationRequest = new PaymentNotificationRequest(paymentToken);
paymentNotificationRequest.setPlatform(PaymentNotificationPlatformCode.Email);
paymentNotificationRequest.setRecipientId("[email protected]");
paymentNotificationRequest.setRecipientName("DavidBilly");
val paymentNotificationRequest = PaymentNotificationRequest(paymentToken).apply {
platform = PaymentNotificationPlatformCode.Email
recipientId = "[email protected]"
recipientName = "DavidBilly"
}
PaymentNotificationRequest *paymentNotificationRequest = [[PaymentNotificationRequest alloc] initWithPaymentToken: paymentToken];
paymentNotificationRequest.platform = PaymentNotificationPlatformCode.Email;
paymentNotificationRequest.recipientId = @"[email protected]";
paymentNotificationRequest.recipientName = @"DavidBilly";
let paymentNotificationRequest: PaymentNotificationRequest = PaymentNotificationRequest(paymentToken: paymentToken)
paymentNotificationRequest.platform = PaymentNotificationPlatformCode.Email
paymentNotificationRequest.recipientId = "[email protected]"
paymentNotificationRequest.recipientName = "DavidBilly"
Map<String, dynamic> paymentNotificationRequest = {
'paymentToken': paymentToken,
'platform': PaymentNotificationPlatformCode.email,
'recipientId': '[email protected]',
'recipientName': 'DavidBilly'
};
let paymentNotificationRequest = {
'paymentToken': paymentToken,
'platform': PaymentNotificationPlatformCode.email,
'recipientId': '[email protected]',
'recipientName': 'DavidBilly'
};
4. Retrieve Payment Notification Response
To retrieve a payment notification response, refer to the parameters below.
Response API Parameters
PGWSDK.getInstance().paymentNotification(paymentNotificationRequest, new APIResponseCallback<PaymentNotificationResponse>() {
@Override
public void onResponse(PaymentNotificationResponse response) {
if(response.getResponseCode().equals(APIResponseCode.APISuccess)) {
//Read payment notification response.
} else {
//Get error response and display error.
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error.
}
});
PGWSDK.getInstance().paymentNotification(paymentNotificationRequest, object : APIResponseCallback<PaymentNotificationResponse> {
override fun onResponse(response: PaymentNotificationResponse) {
if (response.responseCode == APIResponseCode.APISuccess) {
//Read payment notification response.
} else {
//Get error response and display error.
}
}
override fun onFailure(error: Throwable) {
//Get error response and display error.
}
})
[[PGWSDK shared] paymentNotificationWithPaymentNotificationRequest: paymentNotificationRequest response: ^(PaymentNotificationResponse * _Nonnull response) {
if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
//Read payment notification response.
} else {
//Get error response and display error.
}
} failure: ^(NSError * _Nonnull error) {
//Get error response and display error.
}];
PGWSDK.shared.paymentNotification(paymentNotificationRequest: paymentNotificationRequest, { (response: PaymentNotificationResponse) in
if response.responseCode == APIResponseCode.APISuccess {
//Read payment notification response.
} else {
//Get error response and display error.
}
}) { (error: NSError) in
//Get error response and display error.
}
PGWSDK().paymentNotification(paymentNotificationRequest, (response) {
if (response['responseCode'] == APIResponseCode.apiSuccess) {
//Read payment notification response.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
await RTNPGW.paymentNotification(JSON.stringify(paymentNotificationRequest)).then((response: string) => {
let paymentNotificationResponse = JSON.parse(response);
if (paymentNotificationResponse?.responseCode == APIResponseCode.apiSuccess) {
//Read payment notification 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 payment notification request.
PaymentNotificationRequest paymentNotificationRequest = new PaymentNotificationRequest(paymentToken);
paymentNotificationRequest.setPlatform(PaymentNotificationPlatformCode.Email);
paymentNotificationRequest.setRecipientId("[email protected]");
paymentNotificationRequest.setRecipientName("DavidBilly");
//Step 3: Retrieve payment notification response.
PGWSDK.getInstance().paymentNotification(paymentNotificationRequest, new APIResponseCallback<PaymentNotificationResponse>() {
@Override
public void onResponse(PaymentNotificationResponse response) {
if(response.getResponseCode().equals(APIResponseCode.APISuccess)) {
//Read payment notification 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 payment notification request.
val paymentNotificationRequest = PaymentNotificationRequest(paymentToken).apply {
platform = PaymentNotificationPlatformCode.Email
recipientId = "[email protected]"
recipientName = "DavidBilly"
}
//Step 3: Retrieve payment notification response.
PGWSDK.getInstance().paymentNotification(paymentNotificationRequest, object : APIResponseCallback<PaymentNotificationResponse> {
override fun onResponse(response: PaymentNotificationResponse) {
if (response.responseCode == APIResponseCode.APISuccess) {
//Read payment notification 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 payment notification request.
PaymentNotificationRequest *paymentNotificationRequest = [[PaymentNotificationRequest alloc] initWithPaymentToken: paymentToken];
paymentNotificationRequest.platform = PaymentNotificationPlatformCode.Email;
paymentNotificationRequest.recipientId = @"[email protected]";
paymentNotificationRequest.recipientName = @"DavidBilly";
//Step 3: Retrieve payment notification response.
[[PGWSDK shared] paymentNotificationWithPaymentNotificationRequest: paymentNotificationRequest response: ^(PaymentNotificationResponse * _Nonnull response) {
if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
//Read payment notification 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 payment notification request.
let paymentNotificationRequest: PaymentNotificationRequest = PaymentNotificationRequest(paymentToken: paymentToken)
paymentNotificationRequest.platform = PaymentNotificationPlatformCode.Email
paymentNotificationRequest.recipientId = "[email protected]"
paymentNotificationRequest.recipientName = "DavidBilly"
//Step 3: Retrieve payment notification response.
PGWSDK.shared.paymentNotification(paymentNotificationRequest: paymentNotificationRequest, { (response: PaymentNotificationResponse) in
if response.responseCode == APIResponseCode.APISuccess {
//Read payment notification 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 payment notification request.
Map<String, dynamic> paymentNotificationRequest = {
'paymentToken': paymentToken,
'platform': PaymentNotificationPlatformCode.email,
'recipientId': '[email protected]',
'recipientName': 'DavidBilly'
};
//Step 3: Retrieve payment notification response.
PGWSDK().paymentNotification(paymentNotificationRequest, (response) {
if (response['responseCode'] == APIResponseCode.apiSuccess) {
//Read payment notification 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 payment notification request.
let paymentNotificationRequest = {
'paymentToken': paymentToken,
'platform': PaymentNotificationPlatformCode.email,
'recipientId': '[email protected]',
'recipientName': 'DavidBilly'
};
//Step 3: Retrieve payment notification response.
await RTNPGW.paymentNotification(JSON.stringify(paymentNotificationRequest)).then((response: string) => {
let paymentNotificationResponse = JSON.parse(response);
if (paymentNotificationResponse?.responseCode == APIResponseCode.apiSuccess) {
//Read payment notification response.
} else {
//Get error response and display error
}
}).catch ((error: Error) => {
//Get error response and display error
});
Updated 8 days ago