Skip to content

Commit ce791f1

Browse files
author
brianmc
committed
added sample for ChargeCreditCard
1 parent b34180b commit ce791f1

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
<plugin>
2020
<artifactId>maven-assembly-plugin</artifactId>
2121
<executions>
22+
<execution>
23+
<id>ChargeCreditCard</id>
24+
<configuration>
25+
<archive>
26+
<manifest>
27+
<mainClass>net.authorize.sample.PaymentTransactions.ChargeCreditCard</mainClass>
28+
</manifest>
29+
</archive>
30+
<descriptorRefs>
31+
<descriptorRef>jar-with-dependencies</descriptorRef>
32+
</descriptorRefs>
33+
<finalName>ChargeCreditCard</finalName>
34+
</configuration>
35+
<phase>package</phase>
36+
<goals>
37+
<goal>assembly</goal>
38+
</goals>
39+
</execution>
2240
<execution>
2341
<id>visacheckoutdecrypt</id>
2442
<configuration>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package net.authorize.sample.PaymentTransactions;
2+
3+
import java.math.BigDecimal;
4+
5+
import net.authorize.Environment;
6+
import net.authorize.api.contract.v1.*;
7+
import net.authorize.api.controller.base.ApiOperationBase;
8+
import net.authorize.api.controller.CreateTransactionController;
9+
10+
public class ChargeCreditCard {
11+
12+
//
13+
// Run this sample from command line with:
14+
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
15+
//
16+
public static void main(String[] args) {
17+
18+
19+
//Common code to set for all requests
20+
ApiOperationBase.setEnvironment(Environment.SANDBOX);
21+
22+
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
23+
merchantAuthenticationType.setName("5KP3u95bQpv");
24+
merchantAuthenticationType.setTransactionKey("4Ktq966gC55GAX7S");
25+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
26+
27+
// Populate the payment data
28+
PaymentType paymentType = new PaymentType();
29+
CreditCardType creditCard = new CreditCardType();
30+
creditCard.setCardNumber("4242424242424242");
31+
creditCard.setExpirationDate("0822");
32+
paymentType.setCreditCard(creditCard);
33+
34+
// Create the payment transaction request
35+
TransactionRequestType txnRequest = new TransactionRequestType();
36+
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
37+
txnRequest.setPayment(paymentType);
38+
txnRequest.setAmount(new BigDecimal(500.00));
39+
40+
// Make the API Request
41+
CreateTransactionRequest apiRequest = new CreateTransactionRequest();
42+
apiRequest.setTransactionRequest(txnRequest);
43+
CreateTransactionController controller = new CreateTransactionController(apiRequest);
44+
controller.execute();
45+
46+
47+
CreateTransactionResponse response = controller.getApiResponse();
48+
49+
if (response!=null) {
50+
51+
// If API Response is ok, go ahead and check the transaction response
52+
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
53+
54+
TransactionResponse result = response.getTransactionResponse();
55+
if (result.getResponseCode().equals("1")) {
56+
System.out.println(result.getResponseCode());
57+
System.out.println("Successful Credit Card Transaction");
58+
System.out.println(result.getAuthCode());
59+
System.out.println(result.getTransId());
60+
}
61+
else
62+
{
63+
System.out.println("Failed Transaction"+result.getResponseCode());
64+
}
65+
}
66+
else
67+
{
68+
System.out.println("Failed Transaction: "+response.getMessages().getResultCode());
69+
}
70+
}
71+
72+
}
73+
74+
75+
76+
}

0 commit comments

Comments
 (0)