0
votes

I’m attempting to test Accept Hosted payment page(redirect-method) with my sandbox. For this, I’m using the GetAnAcceptPaymentPage from the Java sample code application to generate a token string for a payment, specified the autoLoginId and transactionKey for my sandbox, and setting $1.00 as the amount. I’m then posting the returned token string to https://test.authorize.net/payment/payment with a “token” form element containing that string. This much appears to be working, and I do get a payment page showing the $1.00 amount. However, no matter what values I enter onto that payment page, pressing the “Pay” button just shows “The transaction has been declined.” in red text at the bottom of the form. I’ve confirmed that my sandbox is set to “Live” mode, and have looked at the following link to use what I believe should be valid values for testing: https://developer.authorize.net/hello_world/testing_guide/. I'm hoping someone can tell me why I can't get any result other than "The transaction has been declined".

public String getTokenValue() {
    ApiOperationBase.setEnvironment(Environment.SANDBOX);
    MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
    merchantAuthenticationType.setName("xxxxx");
    merchantAuthenticationType.setTransactionKey("xxxxxx");
    ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);

    // Create the payment transaction request
    TransactionRequestType txnRequest = new TransactionRequestType();
    txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
    txnRequest.setAmount(new BigDecimal(1.00).setScale(2, RoundingMode.CEILING));
    OrderExType order = new OrderExType();
    order.setInvoiceNumber("2");
    txnRequest.setOrder(order);
    CustomerProfilePaymentType cpp = new CustomerProfilePaymentType();
    cpp.setCustomerProfileId("xxxx");
    cpp.setCreateProfile(true);
    txnRequest.setProfile(cpp);

    SettingType setting1 = new SettingType();
    setting1.setSettingName("hostedPaymentButtonOptions");
    setting1.setSettingValue("{\"text\": \"Proceed\"}");

    SettingType setting2 = new SettingType();
    setting2.setSettingName("hostedPaymentOrderOptions");
    setting2.setSettingValue("{\"show\": false}");

    SettingType setting3 = new SettingType();
    setting3.setSettingName("hostedPaymentPaymentOptions");
    setting3.setSettingValue("{\"cardCodeRequired\": true}");

    SettingType setting4 = new SettingType();
    setting4.setSettingName("hostedPaymentIFrameCommunicatorUrl");
    setting4.setSettingValue("{\"url\": \"http://example.com/abc\"}");

    ArrayOfSetting alist = new ArrayOfSetting();
    alist.getSetting().add(setting1);
    alist.getSetting().add(setting2);
    alist.getSetting().add(setting3);
    alist.getSetting().add(setting4);

    GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
    apiRequest.setTransactionRequest(txnRequest);
    apiRequest.setHostedPaymentSettings(alist);

    GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
    controller.execute();
    GetHostedPaymentPageResponse response = new GetHostedPaymentPageResponse();
    response = controller.getApiResponse();

    if (response != null) {

        if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {

            System.out.println(response.getToken());
        } else {
            System.out.println("Failed to get hosted payment page:  " + response.getMessages().getResultCode());
        }
    }
    return response.getToken();
}
1

1 Answers

1
votes

>>> order.setInvoiceNumber("2");

Set the invoice number to a different value than 2, this value is used in Sandbox to trigger decline for testing purposes.