User Address For Payment
Merchants who store customers' billing address information may fill in those details during the customer's checkout process using this API.
API Method
References
Â
1. Prepare Customer Billing Address Details
To prepare the customer's billing address, refer to the parameters below.
UserBillingAddress userBillingAddress = new UserBillingAddress();
userBillingAddress.setAddress1("300 Raffle Place");
userBillingAddress.setAddress2("#20-01");
userBillingAddress.setAddress3("Raffle place building 101");
userBillingAddress.setCity("Singapore");
userBillingAddress.setCountryCode("SG");
userBillingAddress.setPostalCode("32799");
userBillingAddress.setState("Singapore");
UserAddress userAddress = new UserAddressBuilder()
.setUserBillingAddress(userBillingAddress)
.build();
UserBillingAddress *userBillingAddress = [UserBillingAddress alloc];
userBillingAddress.address1 = @"300 Raffle Place";
userBillingAddress.address2 = @"#20-01";
userBillingAddress.address3 = @"Raffle place building 101";
userBillingAddress.city = @"Singapore";
userBillingAddress.countryCode = @"SG";
userBillingAddress.postalCode = @"32799";
userBillingAddress.state = @"Singapore";
UserAddress *userAddress = [[[UserAddressBuilder alloc]
userBillingAddress: userBillingAddress]
build];
let userBillingAddress: UserBillingAddress = UserBillingAddress()
userBillingAddress.address1 = "300 Raffle Place"
userBillingAddress.address2 = "#20-01"
userBillingAddress.address3 = "Raffle place building 101"
userBillingAddress.city = "Singapore"
userBillingAddress.countryCode = "SG"
userBillingAddress.postalCode = "32799"
userBillingAddress.state = "Singapore"
let userAddress: UserAddress = UserAddressBuilder()
.userBillingAddress(userBillingAddress)
.build()
Map<String, dynamic> userAddress = {
'billingAddress1': '30 Raffles Pl',
'billingAddress2': '#32-01',
'billingAddress3': 'CIMB Plaza',
'billingCity': 'Singapore',
'billingState': 'Singapore',
'billingPostalCode': '048622',
'billingCountryCode': 'SG'
};
Â
2. Construct Payment Request
Set the user address in the request
PaymentCode paymentCode = new PaymentCode("CC");
PaymentRequest paymentRequest = new CardPaymentBuilder(paymentCode, "4111111111111111")
.setExpiryMonth(12)
.setExpiryYear(2022)
.setSecurityCode("123")
.setUserAddress(userAddress)
.build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
PaymentRequest *paymentRequest = [[[[[[[CardPaymentBuilder alloc] initWithPaymentCode: paymentCode cardNo: @"4111111111111111"]
expiryMonth: 12]
expiryYear: 2022]
securityCode: @"123"]
userAddress: userAddress]
build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
let paymentRequest: PaymentRequest = CardPaymentBuilder(paymentCode: paymentCode, "4111111111111111")
.expiryMonth(12)
.expiryYear(2022)
.securityCode("123")
.userAddress(userAddress)
.build()
Map<String, dynamic> paymentCode = {
'channelCode': 'CC'
};
Map<String, dynamic> paymentRequest = {
'cardNo': '4111111111111111',
'expiryMonth': 12,
'expiryYear': 2025,
'securityCode': '123',
...userAddress
};
Â
3. Construct Payment Transaction Request
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
.with(paymentRequest)
.build();
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
withPaymentRequest: paymentRequest]
build];
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
.with(paymentRequest)
.build()
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
Â
4. Execute Payment Request
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
@Override
public void onResponse(TransactionResultResponse response) {
if(response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
String redirectUrl = response.getData(); //Open WebView
} else if(response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error.
}
});
[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest response: ^(TransactionResultResponse * _Nonnull response) {
if([response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateRedirect] || [response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateFullRedirect]) {
NSString *redirectUrl = response.data; //Open WebView
} else if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
} failure: ^(NSError * _Nonnull error) {
//Get error response and display error.
}];
PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in
if response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect {
guard let redirectUrl: String = response.data else { return } //Open WebView
} else if response.responseCode == APIResponseCode.TransactionCompleted {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}) { (error: NSError) in
//Get error response and display error.
}
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
Full Sample Code
The following sample code demonstrates parameters and requests for each step of the process.
//Step 1: Construct customer billing address information.
UserBillingAddress userBillingAddress = new UserBillingAddress();
userBillingAddress.setAddress1("300 Raffle Place");
userBillingAddress.setAddress2("#20-01");
userBillingAddress.setAddress3("Raffle place building 101");
userBillingAddress.setCity("Singapore");
userBillingAddress.setCountryCode("SG");
userBillingAddress.setPostalCode("32799");
userBillingAddress.setState("Singapore");
UserAddress userAddress = new UserAddressBuilder()
.setUserBillingAddress(userBillingAddress)
.build();
//Step 2: Construct payment request and add user address into request.
PaymentCode paymentCode = new PaymentCode("CC");
PaymentRequest paymentRequest = new CardPaymentBuilder(paymentCode, "4111111111111111")
.setExpiryMonth(12)
.setExpiryYear(2022)
.setSecurityCode("123")
.setUserAddress(userAddress)
.build();
//Step 3: Construct transaction request.
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
.with(paymentRequest)
.build();
//Step 4: Execute payment request.
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
@Override
public void onResponse(TransactionResultResponse response) {
if(response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
String redirectUrl = response.getData(); //Open WebView
} else if(response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error.
}
});
//Step 1: Construct customer billing address information.
UserBillingAddress *userBillingAddress = [UserBillingAddress alloc];
userBillingAddress.address1 = @"300 Raffle Place";
userBillingAddress.address2 = @"#20-01";
userBillingAddress.address3 = @"Raffle place building 101";
userBillingAddress.city = @"Singapore";
userBillingAddress.countryCode = @"SG";
userBillingAddress.postalCode = @"32799";
userBillingAddress.state = @"Singapore";
UserAddress *userAddress = [[[UserAddressBuilder alloc]
userBillingAddress: userBillingAddress]
build];
//Step 2: Construct payment request and add user address into request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
PaymentRequest *paymentRequest = [[[[[[[CardPaymentBuilder alloc] initWithPaymentCode: paymentCode cardNo: @"4111111111111111"]
expiryMonth: 12]
expiryYear: 2022]
securityCode: @"123"]
userAddress: userAddress]
build];
//Step 3: Construct transaction request.
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
withPaymentRequest: paymentRequest]
build];
//Step 4: Execute payment request.
[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest response: ^(TransactionResultResponse * _Nonnull response) {
if([response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateRedirect] || [response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateFullRedirect]) {
NSString *redirectUrl = response.data; //Open WebView
} else if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
} failure: ^(NSError * _Nonnull error) {
//Get error response and display error.
}];
//Step 1: Construct customer billing address information.
let userBillingAddress: UserBillingAddress = UserBillingAddress()
userBillingAddress.address1 = "300 Raffle Place"
userBillingAddress.address2 = "#20-01"
userBillingAddress.address3 = "Raffle place building 101"
userBillingAddress.city = "Singapore"
userBillingAddress.countryCode = "SG"
userBillingAddress.postalCode = "32799"
userBillingAddress.state = "Singapore"
let userAddress: UserAddress = UserAddressBuilder()
.userBillingAddress(userBillingAddress)
.build()
//Step 2: Construct payment request and add user address into request.
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
let paymentRequest: PaymentRequest = CardPaymentBuilder(paymentCode: paymentCode, "4111111111111111")
.expiryMonth(12)
.expiryYear(2022)
.securityCode("123")
.userAddress(userAddress)
.build()
//Step 3: Construct transaction request.
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
.with(paymentRequest)
.build()
//Step 4: Execute payment request.
PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in
if response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect {
guard let redirectUrl: String = response.data else { return } //Open WebView
} else if response.responseCode == APIResponseCode.TransactionCompleted {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}) { (error: NSError) in
//Get error response and display error.
}
//Step 1: Construct customer billing address information.
Map<String, dynamic> userAddress = {
'billingAddress1': '30 Raffles Pl',
'billingAddress2': '#32-01',
'billingAddress3': 'CIMB Plaza',
'billingCity': 'Singapore',
'billingState': 'Singapore',
'billingPostalCode': '048622',
'billingCountryCode': 'SG'
};
//Step 2: Construct payment request and add user address into request.
Map<String, dynamic> paymentCode = {
'channelCode': 'CC'
};
Map<String, dynamic> paymentRequest = {
'cardNo': '4111111111111111',
'expiryMonth': 12,
'expiryYear': 2025,
'securityCode': '123',
...userAddress
};
//Step 3: Construct transaction request
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
//Step 4: Execute payment request.
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
Updated 4 months ago