Coder Social home page Coder Social logo

sample-code-java's Introduction

Java Sample Code for the Authorize.Net SDK

Travis CI Status

This repository contains working code samples which demonstrate Java integration with the Authorize.Net Java SDK.

The samples are organized into categories and common usage examples, just like our API Reference Guide. Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide.

Using the Sample Code

The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project.

You can also run each sample directly from the command line.

Running the Samples From the Command Line

  • Clone this repository:
    $ git clone https://github.com/AuthorizeNet/sample-code-java.git
  • Run "mvn package" in the root directory to create the SampleCode console app.
  • Run the individual samples by name. For example:
     > java -jar target/SampleCode.jar [CodeSampleName]

e.g.

     > java -jar target/SampleCode.jar ChargeCreditCard

Running SampleCode without a parameter will give you the list of sample names.

NOTE : You can update to your Sandbox credentials in SampleCode.java

For using behind proxy

Please set the JAVA environment proxy using a similar code :

    System.setProperty(Constants.HTTPS_USE_PROXY, "true");
    System.setProperty(Constants.HTTPS_PROXY_HOST, "127.0.0.1");
    System.setProperty(Constants.HTTPS_PROXY_PORT, "8888");

For using proxy authentication

Please set the JAVA environment proxy credentials using a similar code :

    System.setProperty(Constants.HTTPS_PROXY_USERNAME, "exampleUsername");
    System.setProperty(Constants.HTTPS_PROXY_PASSWORD, "examplePassword");

sample-code-java's People

Contributors

adavidw avatar akankaria avatar akashshah1203 avatar anuragg29 avatar anuvaradha avatar ashtru avatar brianmc avatar gnongsie avatar gnongsiej avatar karthikeyanrzp avatar khaaldrogo avatar kikmak42 avatar metroid-samus avatar nagarikantipavan avatar namanbansal avatar rahulrnitc avatar sapbasu15 avatar vsavaradha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-code-java's Issues

Sample Code throwing exception

I am trying to run the sample app with java 11 but getting below error. Any help in this regard is appreciated.

Task :ChargeCreditCard.main()
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at net.authorize.util.HttpUtility.postData(HttpUtility.java:101)
at net.authorize.api.controller.base.ApiOperationBase.execute(ApiOperationBase.java:145)
at net.authorize.api.controller.base.ApiOperationBase.execute(ApiOperationBase.java:133)
at net.authorize.sample.PaymentTransactions.ChargeCreditCard.run(ChargeCreditCard.java:56)
at net.authorize.sample.PaymentTransactions.ChargeCreditCard.main(ChargeCreditCard.java:15)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.bas

Screenshot 2024-06-10 at 11 30 27 AM

Critical: OK is not reliable to check if a transaction was successful

Your example code says in multiple places to check for "OK" in the resultCode to check if a transaction has been successful:
https://github.com/AuthorizeNet/sample-code-java/blob/master/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCreditCard.java#L61
https://github.com/AuthorizeNet/sample-code-java/blob/master/src/main/java/net/authorize/sample/PaymentTransactions/ChargeCustomerProfile.java#L63

Below is a screenshot of an actual Authorize.NET decline response, triggered by sending the zip code 46282.

Screenshot from 2019-04-04 15-29-53

As you can see, resultCode is OK. But this transaction is declined.

This is a serious issue as if someone uses your sample code, declines will be processed as if they were successful. E.g. Orders could go through without payment.

What I've found is that its more reliable to check the responseCode instead (e.g. "2" for decline). This is how I worked around this issue.

It would be interesting to know if "OK" is intended to be there for declines, or is this a bug on the server side in Authorize.NET?

Java code is missing

First of all many thank you for such a nice tutorials. However I don't find the following files have any code. Could you please update code for the sameASAP?

  • CreateSubscription.java
  • GetUnsettledTransactions.java
  • CreateCustomerProfile.java

Inability to run Visa Checkout sample codes for the SampleCode.java

In the SampleCode.java, while displaying the options for choosing which sample code to run (Code Sample Names), the displayed options are:
DecryptVisaCheckoutData
CreateVisaCheckoutTransaction

However, in the switch case the case operands are named differently.
case "VisaCheckoutDecrypt":
DecryptVisaCheckoutData.run(apiLoginId, transactionKey);
break;
case "VisaCheckoutTransaction":
CreateVisaCheckoutTransaction.run(apiLoginId, transactionKey);
break;

This causes both these sample code to never run from the SampleCode.java.

Cant run ValidateCustomerPaymentProfile.

In SampleCode.java, in the displayed list of option of sample codes ValidateCustomerPaymentProfile is not there. There is no case expression for it also. Thus one can't run ValidateCustomerPaymentProfile using the SampleCode.java.

How To Set Trail Day in Java

There are only Two parameter
1.setTrialAmount(Transaction.ZERO_AMOUNT);
2.setTrialOccurrences(1);
No Trail Period in authoize.net

TLS Disablement

I can't seem to get these samples to run in Java 7. The issue seems to be related to TLS Disablement in the sandbox environment and the fact that TLS 1.2 is supported, but not enabled by default in Java 7. This also seems be be the cause of this build failing in Travis.

I have been trying for a solution for a few days without success. Is there an ETA on Authorize.net providing a solution? -Or is Java 7 support going to be discontinued?

Getting exceptions on New Model

For responses in New Model in https://github.com/AuthorizeNet/sdk-java/, I tried the sample code on this page and sample code on https://github.com/AuthorizeNet/sample-code-java/blob/master/src/main/java/net/authorize/sample/RecurringBilling/GetListOfSubscriptions.java

I got the same exceptions:
[error] n.a.u.HttpUtility - Execution error for http post Message: 'java.lang.Ar
rayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy'

and the response is always null due to this exception.

same as other types of request/response in New Model of ARB.

Can anybody take a look?

Thanks.

Refund example not complete

Hi, first of all thank you for such a good examples.

It seems to me that refund example: https://github.com/AuthorizeNet/sample-code-java/blob/master/src/main/java/net/authorize/sample/PaymentTransactions/RefundTransaction.java is not complete.

From example I would say that credit card number is not needed for transaction to be refunded. But when I tried to reuse example I cannot refund money to user.
Error that I got in xml response is: Credit card number is required.

In ruby example there is credit card number that need to be submitted in order to refund money: https://github.com/AuthorizeNet/sample-code-ruby/blob/master/PaymentTransactions/refund-transaction.rb

Also from example I cannot tell how can I set amount of money that will be refunded.

Could you please tell me if this information is really missing in example or I am doing something wrong?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.