-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathInstamojoExample.java
More file actions
131 lines (106 loc) · 4.34 KB
/
InstamojoExample.java
File metadata and controls
131 lines (106 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.instamojo.wrapper.api;
import com.instamojo.wrapper.exception.ConnectionException;
import com.instamojo.wrapper.exception.HTTPException;
import com.instamojo.wrapper.model.PaymentOrder;
import com.instamojo.wrapper.model.PaymentOrderResponse;
import com.instamojo.wrapper.model.Refund;
import com.instamojo.wrapper.response.ApiListResponse;
public class InstamojoExample {
public static void main(String[] args) {
/*
* Get a reference to the instamojo api
*/
ApiContext context = ApiContext.create("[PARAM_CLIENT_ID]", "[PARAM_CLIENT_SECRET]", ApiContext.Mode.TEST);
Instamojo api = new InstamojoImpl(context);
/*
* Create a new payment order
*/
PaymentOrder order = new PaymentOrder();
order.setName("John Smith");
order.setEmail("john.smith@gmail.com");
order.setPhone("12345678790");
order.setCurrency("INR");
order.setAmount(9D);
order.setDescription("This is a test transaction.");
order.setRedirectUrl("http://www.someexample.com");
order.setWebhookUrl("http://www.someurl.com/");
order.setTransactionId("dxg234");
try {
PaymentOrderResponse paymentOrderResponse = api.createPaymentOrder(order);
System.out.println(paymentOrderResponse.getPaymentOrder().getStatus());
} catch (HTTPException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getMessage());
System.out.println(e.getJsonPayload());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
/*
* Get details of payment order when order id is given
*/
try {
PaymentOrder paymentOrder = api.getPaymentOrder("[PAYMENT_ORDER_ID]");
System.out.println(paymentOrder.getId());
System.out.println(paymentOrder.getStatus());
} catch (HTTPException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getMessage());
System.out.println(e.getJsonPayload());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
/*
* Get details of payment order when transaction id is given
*/
try {
PaymentOrder paymentOrder = api.getPaymentOrderByTransactionId("[TRANSACTION_ID]");
System.out.println(paymentOrder.getId());
System.out.println(paymentOrder.getStatus());
} catch (HTTPException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getMessage());
System.out.println(e.getJsonPayload());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
/*
* Get list of all payment orders
*/
try {
ApiListResponse<PaymentOrder> paymentOrders = api.getPaymentOrders(0, 10);
// Loop over all of the payment orders and print status of each
// payment order.
for (PaymentOrder paymentOrder : paymentOrders.getResults()) {
System.out.println("Result = " + paymentOrder.getStatus());
}
System.out.println(paymentOrders);
} catch (HTTPException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getMessage());
System.out.println(e.getJsonPayload());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
/*
* Create a new refund
*/
Refund refund = new Refund();
refund.setPaymentId("[PaymentId]");
refund.setStatus("refunded");
refund.setType("RFD");
refund.setBody("This is a test refund.");
refund.setRefundAmount(9D);
refund.setTotalAmount(10D);
try {
Refund createdRefund = api.createRefund(refund);
System.out.println(createdRefund.getId());
System.out.println(createdRefund.getStatus());
} catch (HTTPException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getMessage());
System.out.println(e.getJsonPayload());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}