| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,98 @@ | |||
| 1 | + package net.authorize.sample.MobileInAppTransactions; | ||
| 2 | + | ||
| 3 | + import net.authorize.Environment; | ||
| 4 | + import net.authorize.api.contract.v1.*; | ||
| 5 | + import net.authorize.api.controller.CreateTransactionController; | ||
| 6 | + import net.authorize.api.controller.base.ApiOperationBase; | ||
| 7 | + | ||
| 8 | + import java.math.BigDecimal; | ||
| 9 | + | ||
| 10 | + public class CreateGooglePayTransaction { | ||
| 11 | + public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) { | ||
| 12 | + ApiOperationBase.setEnvironment(Environment.SANDBOX); | ||
| 13 | + | ||
| 14 | + MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType(); | ||
| 15 | + merchantAuthenticationType.setName(apiLoginId); | ||
| 16 | + merchantAuthenticationType.setTransactionKey(transactionKey); | ||
| 17 | + ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType); | ||
| 18 | + | ||
| 19 | + OpaqueDataType opaqueData = new OpaqueDataType(); | ||
| 20 | + opaqueData.setDataDescriptor("COMMON.GOOGLE.INAPP.PAYMENT"); | ||
| 21 | + opaqueData.setDataValue("1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000"); | ||
| 22 | + | ||
| 23 | + PaymentType paymentType = new PaymentType(); | ||
| 24 | + paymentType.setOpaqueData(opaqueData); | ||
| 25 | + | ||
| 26 | + LineItemType lineItem = new LineItemType(); | ||
| 27 | + lineItem.setItemId("1"); | ||
| 28 | + lineItem.setName("vase"); | ||
| 29 | + lineItem.setDescription("Cannes logo"); | ||
| 30 | + lineItem.setQuantity(BigDecimal.valueOf(18)); | ||
| 31 | + lineItem.setUnitPrice(BigDecimal.valueOf(45.00)); | ||
| 32 | + | ||
| 33 | + ArrayOfLineItem lineItems = new ArrayOfLineItem(); | ||
| 34 | + lineItems.getLineItem().add(lineItem); | ||
| 35 | + | ||
| 36 | + ExtendedAmountType tax = new ExtendedAmountType(); | ||
| 37 | + tax.setAmount(BigDecimal.valueOf(amount)); | ||
| 38 | + tax.setName("level2 tax name"); | ||
| 39 | + tax.setDescription("level2 tax"); | ||
| 40 | + | ||
| 41 | + UserField userField = new UserField(); | ||
| 42 | + TransactionRequestType.UserFields userFields = new TransactionRequestType.UserFields(); | ||
| 43 | + | ||
| 44 | + userField.setName("UserDefinedFieldName1"); | ||
| 45 | + userField.setValue("UserDefinedFieldValue1"); | ||
| 46 | + userFields.getUserField().add(userField); | ||
| 47 | + | ||
| 48 | + userField.setName("UserDefinedFieldName2"); | ||
| 49 | + userField.setValue("UserDefinedFieldValue2"); | ||
| 50 | + userFields.getUserField().add(userField); | ||
| 51 | + | ||
| 52 | + TransactionRequestType transactionRequest = new TransactionRequestType(); | ||
| 53 | + transactionRequest.setAmount(BigDecimal.valueOf(amount)); | ||
| 54 | + transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value()); | ||
| 55 | + transactionRequest.setPayment(paymentType); | ||
| 56 | + | ||
| 57 | + CreateTransactionRequest apiRequest = new CreateTransactionRequest(); | ||
| 58 | + apiRequest.setTransactionRequest(transactionRequest); | ||
| 59 | + | ||
| 60 | + CreateTransactionController controller = new CreateTransactionController(apiRequest); | ||
| 61 | + controller.execute(); | ||
| 62 | + | ||
| 63 | + CreateTransactionResponse response = controller.getApiResponse(); | ||
| 64 | + | ||
| 65 | + if (response!=null) { | ||
| 66 | + // If API Response is ok, go ahead and check the transaction response | ||
| 67 | + if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { | ||
| 68 | + TransactionResponse result = response.getTransactionResponse(); | ||
| 69 | + if (result.getMessages() != null) { | ||
| 70 | + System.out.println("Successfully created transaction with Transaction ID: " + result.getTransId()); | ||
| 71 | + System.out.println("Response Code: " + result.getResponseCode()); | ||
| 72 | + System.out.println("Message Code: " + result.getMessages().getMessage().get(0).getCode()); | ||
| 73 | + System.out.println("Description: " + result.getMessages().getMessage().get(0).getDescription()); | ||
| 74 | + System.out.println("Auth code : " + result.getAuthCode()); | ||
| 75 | + } else { | ||
| 76 | + System.out.println("Failed Transaction."); | ||
| 77 | + if (response.getTransactionResponse().getErrors() != null) { | ||
| 78 | + System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); | ||
| 79 | + System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + } else { | ||
| 83 | + System.out.println("Failed Transaction."); | ||
| 84 | + if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) { | ||
| 85 | + System.out.println("Error Code: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()); | ||
| 86 | + System.out.println("Error message: " + response.getTransactionResponse().getErrors().getError().get(0).getErrorText()); | ||
| 87 | + } else { | ||
| 88 | + System.out.println("Error Code: " + response.getMessages().getMessage().get(0).getCode()); | ||
| 89 | + System.out.println("Error message: " + response.getMessages().getMessage().get(0).getText()); | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + } else { | ||
| 93 | + System.out.println("Null Response."); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + return response; | ||
| 97 | + } | ||
| 98 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,7 @@ private static void ShowMethods() { | |||
| 83 | 83 | System.out.println(" CreateAnApplePayTransaction"); | |
| 84 | 84 | System.out.println(" CreateAnAndroidPayTransaction"); | |
| 85 | 85 | System.out.println(" CreateAnAcceptTransaction"); | |
| 86 | + System.out.println(" CreateGooglePayTransaction"); | ||
| 86 | 87 | System.out.println(" ChargeCustomerProfile"); | |
| 87 | 88 | System.out.println(" CreateSubscription"); | |
| 88 | 89 | System.out.println(" CreateSubscriptionFromCustomerProfile"); | |
@@ -205,6 +206,8 @@ private static void RunMethod(String methodName) { | |||
| 205 | 206 | case "CreateAnAcceptTransaction": | |
| 206 | 207 | CreateAnAcceptTransaction.run(apiLoginId, transactionKey); | |
| 207 | 208 | break; | |
| 209 | + case "CreateGooglePayTransaction": | ||
| 210 | + CreateGooglePayTransaction.run(apiLoginId, transactionKey, amount); | ||
| 208 | 211 | case "ChargeCustomerProfile": | |
| 209 | 212 | ChargeCustomerProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId, amount); | |
| 210 | 213 | break; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments