Repository navigation
Expand file tree
/
Copy pathBitPayTest2.java
More file actions
86 lines (75 loc) · 3.17 KB
/
Copy pathBitPayTest2.java
File metadata and controls
86 lines (75 loc) · 3.17 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
package test;
import com.bitpay.sdk.BitPayException;
import com.bitpay.sdk.Client;
import com.bitpay.sdk.Env;
import com.bitpay.sdk.model.Currency;
import com.bitpay.sdk.model.Facade;
import com.bitpay.sdk.model.Invoice.Invoice;
import com.bitpay.sdk.util.BitPayLogger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.net.UnknownHostException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BitPayTest2 {
private static final BitPayLogger _log = new BitPayLogger(BitPayLogger.DEBUG);
private static String clientName = "BitPay Java Library Tester2";
private Client bitpay;
@BeforeClass
public static void setUpOneTime() throws UnknownHostException, BitPayException {
// Client bitpay = new Client("BitPay.config.json", null);
Client bitpay = new Client(
Env.Test,
"bitpay_private_test.key",
new Env.Tokens() {{
pos = "AvJdGrEqTW9HVsJit9zabAnrJabqaQDhWHRacHYgfgxK";
merchant = "2smKkjA1ACPKWUGN7wUEEqdWi3rhXYhDX6AKgG4njKvj";
payroll = "9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo";
}},
null
);
if (!bitpay.tokenExist(Facade.PointOfSale)) {
// Get POS facade authorization code.
// Obtain a pairingCode from the BitPay server. The pairingCode must be emitted from
// this device and input into and approved by the desired merchant account. To
// generate invoices a POS facade is required.
String pairingCode = bitpay.requestClientAuthorization(Facade.PointOfSale);
// Signal the device operator that this client needs to be paired with a merchant account.
_log.info("Client is requesting POS facade access. Go to " + Env.TestUrl + " and pair this client with your merchant account using the pairing code: " + pairingCode);
throw new BitPayException("Error: client is not authorized.");
}
bitpay.setLoggerLevel(BitPayLogger.DEBUG);
}
@Before
public void setUp() throws BitPayException {
//ensure the second argument (api url) is the same as the one used in setUpOneTime()
// bitpay = new Client("BitPay.config.json", null);
bitpay = new Client(
Env.Test,
"bitpay_private_test.key",
new Env.Tokens() {{
pos = "AvJdGrEqTW9HVsJit9zabAnrJabqaQDhWHRacHYgfgxK";
merchant = "2smKkjA1ACPKWUGN7wUEEqdWi3rhXYhDX6AKgG4njKvj";
payroll = "9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo";
}},
null
);
}
@Test
public void testShouldGetInvoiceId() {
Invoice invoice = new Invoice(1.00, "USD");
try {
invoice = bitpay.createInvoice(invoice);
} catch (Exception e) {
e.printStackTrace();
}
assertNotNull(invoice.getId());
}
@Test
public void testCurrency() {
boolean validCurrency;
validCurrency = Currency.isValid("EUR");
assertTrue(validCurrency);
}
}