暂无官方文档显示Authorize.net直接支持GraalVM,但是可以通过使用支持Java的GraalVM,将Authorize.net Java SDK添加到GraalVM项目中,从而实现与Authorize.net的交互。以下是附加到GraalVM项目的Java代码示例:
import net.authorize.sim.MessageHandler;
import net.authorize.Environment;
import net.authorize.api.contract.v1.*;
import net.authorize.api.controller.*;
import net.authorize.api.controller.base.*;
import net.authorize.data.xml.reporting.TransactionDetails;
import net.authorize.reporting.reportingapi.*;
import java.math.BigDecimal;
public class AuthorizeNetExample {
public static void main(String[] args) {
final String apiLoginID = "YOUR_API_LOGIN_ID";
final String transactionKey = "YOUR_TRANSACTION_KEY";
// COMMON API VARIABLES
String apiEndPoint = Environment.SANDBOX.getXmlValue();
ApiOperationBase.setEnvironment(Environment.SANDBOX);
// CREATE CUSTOMER PROFILE
CreateCustomerProfileResponseType responseCreateCustomer = createAuthorizeNetCustomerProfile(apiLoginID, transactionKey, apiEndPoint);
if (responseCreateCustomer != null) {
String customerProfileId = responseCreateCustomer.getCustomerProfileId();
String customerPaymentProfileId = responseCreateCustomer.getCustomerPaymentProfileIdList().get(0);
// PROCESS CREDIT CARD CHARGE
ChargeCreditCardResponseType responseChargeCreditCard = chargeAuthorizeNetCreditCard(apiLoginID, transactionKey, customerProfileId, customerPaymentProfileId, new BigDecimal("1.00"), apiEndPoint);
if (responseChargeCreditCard != null) {
String transactionId = responseChargeCreditCard.getTransactionResponse().getTransId();
// GET TRANSACTION DETAILS WITH REPORTING API
ReportTransactionResponseType responseReportTransaction = reportTransaction(apiLoginID, transactionKey, transactionId, apiEndPoint);
if (responseReportTransaction != null) {
TransactionDetails transactionDetails = responseReportTransaction.getTransaction().getTransactionDetails();
// OUTPUT TRANSACTION DETAILS
System.out.println("Transaction Id: " + transactionDetails.getTransId());
System.out.println("Transaction Status: " + transactionDetails.getTransactionStatus());
System.out.println("Amount Charged: " + transactionDetails.getSettleAmount().toString());
System.out.println("Approval Code: " + transactionDetails.getAuthCode());
}
}
}
}
public static CreateCustomerProfileResponseType createAuthorizeNetCustomerProfile(String apiLoginID, String transactionKey, String apiEndPoint) {
MerchantAuthenticationType merchantAuthenticationType = getMerchantAuthenticationType(apiLoginID, transactionKey);
CustomerProfileType customerProfileType = new CustomerProfileType();
customerProfileType.setDescription("Java SDK Example");
CreateCustomerProfile