Skip to content

Commit c3f21e4

Browse files
committed
Added Sample Accept & AndroidPay
1 parent 47a46c6 commit c3f21e4

5 files changed

Lines changed: 147 additions & 5 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package net.authorize.sample.MobileInAppTransactions;
2+
3+
import java.math.BigDecimal;
4+
import net.authorize.Environment;
5+
import net.authorize.TransactionType;
6+
import net.authorize.api.contract.v1.*;
7+
import net.authorize.api.controller.CreateTransactionController;
8+
import net.authorize.api.controller.base.ApiOperationBase;
9+
10+
public class CreateAnAcceptTransaction
11+
{
12+
public static ANetApiResponse run(String apiLoginId, String transactionKey)
13+
{
14+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
15+
16+
// Giving the merchant authentication information
17+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
18+
merchantAuthenticationType.setName(apiLoginId);
19+
merchantAuthenticationType.setTransactionKey(transactionKey);
20+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
21+
// Setting the payment
22+
OpaqueDataType op = new OpaqueDataType();
23+
op.setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
24+
op.setDataValue("9471471570959063005001");
25+
PaymentType paymentOne = new PaymentType();
26+
paymentOne.setOpaqueData(op);
27+
// Setting the transaction
28+
TransactionRequestType transactionRequest = new TransactionRequestType();
29+
transactionRequest.setAmount(new BigDecimal("131"));
30+
transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
31+
transactionRequest.setPayment(paymentOne);
32+
// Making the api request
33+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
34+
apiRequest.setTransactionRequest(transactionRequest);
35+
// Creating the controller
36+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
37+
controller.execute();
38+
// Getting the response
39+
CreateTransactionResponse response = controller.getApiResponse();
40+
if(response!=null)
41+
{
42+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK)
43+
{
44+
if (response.getTransactionResponse() != null)
45+
{
46+
TransactionResponse result = response.getTransactionResponse();
47+
System.out.println("Successful: Create an Accept Transaction");
48+
System.out.println("Response Code : " + result.getResponseCode());
49+
System.out.println("Transaction ID : " + result.getTransId());
50+
System.out.println("Auth code : " + result.getAuthCode());
51+
}
52+
}
53+
else
54+
{
55+
56+
System.out.println("Failed: Create Accept Transaction");
57+
if(!response.getMessages().getMessage().isEmpty())
58+
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
59+
60+
if (response.getTransactionResponse() != null)
61+
if(response.getTransactionResponse().getErrors() != null && !response.getTransactionResponse().getErrors().getError().isEmpty())
62+
System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
63+
}
64+
}
65+
return response;
66+
}
67+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package net.authorize.sample.MobileInAppTransactions;
2+
3+
import java.math.BigDecimal;
4+
import net.authorize.Environment;
5+
import net.authorize.TransactionType;
6+
import net.authorize.api.contract.v1.*;
7+
import net.authorize.api.controller.CreateTransactionController;
8+
import net.authorize.api.controller.base.ApiOperationBase;
9+
10+
public class CreateAnAndroidPayTransaction
11+
{
12+
public static ANetApiResponse run(String apiLoginId, String transactionKey)
13+
{
14+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
15+
16+
// Giving the merchant authentication information
17+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
18+
merchantAuthenticationType.setName(apiLoginId);
19+
merchantAuthenticationType.setTransactionKey(transactionKey);
20+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
21+
// Setting the payment
22+
OpaqueDataType op = new OpaqueDataType();
23+
op.setDataDescriptor("COMMON.ANDROID.INAPP.PAYMENT");
24+
op.setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVV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
PaymentType paymentOne = new PaymentType();
26+
paymentOne.setOpaqueData(op);
27+
// Setting the transaction
28+
TransactionRequestType transactionRequest = new TransactionRequestType();
29+
transactionRequest.setAmount(new BigDecimal("131"));
30+
transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
31+
transactionRequest.setPayment(paymentOne);
32+
// Making the api request
33+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
34+
apiRequest.setTransactionRequest(transactionRequest);
35+
// Creating the controller
36+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
37+
controller.execute();
38+
// Getting the response
39+
CreateTransactionResponse response = controller.getApiResponse();
40+
if(response!=null)
41+
{
42+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK)
43+
{
44+
if (response.getTransactionResponse() != null)
45+
{
46+
TransactionResponse result = response.getTransactionResponse();
47+
System.out.println("Successful: Create an AndroidPay Transaction");
48+
System.out.println("Response Code : " + result.getResponseCode());
49+
System.out.println("Transaction ID : " + result.getTransId());
50+
System.out.println("Auth code : " + result.getAuthCode());
51+
}
52+
}
53+
else
54+
{
55+
System.out.println("Failed: Create AndroidPay Transaction");
56+
if(!response.getMessages().getMessage().isEmpty())
57+
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
58+
59+
if (response.getTransactionResponse() != null)
60+
if(response.getTransactionResponse().getErrors() != null && !response.getTransactionResponse().getErrors().getError().isEmpty())
61+
System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
62+
}
63+
}
64+
return response;
65+
}
66+
}

src/main/java/net/authorize/sample/ApplePayTransactions/CreateAnApplePayTransaction.java renamed to src/main/java/net/authorize/sample/MobileInAppTransactions/CreateAnApplePayTransaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.authorize.sample.ApplePayTransactions;
1+
package net.authorize.sample.MobileInAppTransactions;
22

33
import java.math.BigDecimal;
44
import net.authorize.Environment;
@@ -57,7 +57,7 @@ public static ANetApiResponse run(String apiLoginId, String transactionKey)
5757
System.out.println("Error: " + response.getMessages().getMessage().get(0).getCode() + " " + response.getMessages().getMessage().get(0).getText());
5858

5959
if (response.getTransactionResponse() != null)
60-
if(!response.getTransactionResponse().getErrors().getError().isEmpty())
60+
if(response.getTransactionResponse().getErrors() != null && !response.getTransactionResponse().getErrors().getError().isEmpty())
6161
System.out.println("Transaction Error : " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode() + " " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText());
6262
}
6363
}

‎src/main/java/net/authorize/sample/SampleCode.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.BufferedReader;
44
import java.io.IOException;
55
import java.io.InputStreamReader;
6-
import net.authorize.sample.ApplePayTransactions.CreateAnApplePayTransaction;
76

87
import net.authorize.sample.VisaCheckout.*;
98
import net.authorize.sample.PaymentTransactions.*;
@@ -12,7 +11,7 @@
1211
import net.authorize.sample.RecurringBilling.*;
1312
import net.authorize.sample.TransactionReporting.*;
1413
import net.authorize.sample.CustomerProfiles.*;
15-
import net.authorize.sample.ApplePayTransactions.*;
14+
import net.authorize.sample.MobileInAppTransactions.*;
1615
/**
1716
* Created by anetdeveloper on 8/5/15.
1817
*/
@@ -87,6 +86,8 @@ private static void ShowMethods()
8786
System.out.println(" CreditBankAccount");
8887
System.out.println(" ChargeTokenizedCreditCard");
8988
System.out.println(" CreateAnApplePayTransaction");
89+
System.out.println(" CreateAnAndroidPayTransaction");
90+
System.out.println(" CreateAnAcceptTransaction");
9091
System.out.println(" ChargeCustomerProfile");
9192
System.out.println(" CreateSubscription");
9293
System.out.println(" CreateSubscriptionFromCustomerProfile");
@@ -187,6 +188,12 @@ private static void RunMethod(String methodName)
187188
case "CreateAnApplePayTransaction":
188189
CreateAnApplePayTransaction.run(apiLoginId, transactionKey);
189190
break;
191+
case "CreateAnAndroidPayTransaction":
192+
CreateAnAndroidPayTransaction.run(apiLoginId, transactionKey);
193+
break;
194+
case "CreateAnAcceptTransaction":
195+
CreateAnAcceptTransaction.run(apiLoginId, transactionKey);
196+
break;
190197
case "ChargeCustomerProfile":
191198
ChargeCustomerProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId, amount);
192199
break;

‎src/test/java/net/authorize/sample/SampleCodeTest/SampleCodeList.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ TransactionReporting.GetUnsettledTransactionList 0 1
4747
TransactionReporting.GetBatchStatistics 0 1
4848
TransactionReporting.GetSettledBatchList 0 1
4949
TransactionReporting.GetTransactionDetails 1 1
50-
ApplePayTransactions.CreateAnApplePayTransaction 0 0
50+
MobileInAppTransactions.CreateAnApplePayTransaction 0 0
51+
MobileInAppTransactions.CreateAnAndroidPayTransaction 0 0
52+
MobileInAppTransactions.CreateAnAcceptTransaction 0 0
5153
VisaCheckout.DecryptVisaCheckoutData 0 1
5254
VisaCheckout.CreateVisaCheckoutTransaction 0 0

0 commit comments

Comments
 (0)