- 确认使用的是Amazon Pay API版本4或更新。
- 查询订单状态并获取Authorization ID。
- 通过Authorization ID执行UpdateAuthorization API调用,并将配送信息(AddressInformation)包含在MerchantAuthorizationAttributes对象中。这将更新授权金额并更新客户配送地址。
- 以下示例演示了如何使用Amazon Pay API更新授权金额和地址信息:
public void updateAuthorizationAmountAndAddress(String authorizationId, AddressInformation newAddress, Price newAmount) {
try {
MerchantAuthorizationAttributes attributes = new MerchantAuthorizationAttributes();
attributes.setAuthorizationAmount(newAmount);
attributes.setAddressInformation(newAddress);
UpdateAuthorizationRequest updateAuthorizationRequest = new UpdateAuthorizationRequest();
updateAuthorizationRequest.setMerchantAuthorizationAttributes(attributes);
AmazonPayClient client = new AmazonPayClient(config);
UpdateAuthorizationResponse response = client.updateAuthorization(updateAuthorizationRequest, authorizationId);
System.out.println("Authorization updated, new amount: " + response.getResponseMetadata().getRequestId());
} catch (ErrorResponseException e) {
System.err.println("Unable to update authorization amount/address, error response:");
System.err.println("Error code: " + e.getErrorCode());
System.err.println("Error message: " + e.getErrorMessage());
} catch (Exception e) {
System.err.println("Unable to update authorization amount/address, error message:");
System.err.println(e.getMessage());
}
}