Skip to content

Commit c2b3e15

Browse files
author
Antonio Buedo
authored
#v3.0 - v3 architecture standard implemented (#47)
* - Init from conf file implemented * - Version upgrade * - Standard Client constructors implemented * - Guide updated * - Readme updated * - Doc updated * - Code cleanup * - Code refactor
1 parent 69611e9 commit c2b3e15

File tree

127 files changed

+2078
-1238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2078
-1238
lines changed

GUIDE.md

Lines changed: 68 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## Using BitPay Java Client Library
1+
## Using the BitPay Java client
22

33
This SDK provides a convenient abstraction of BitPay's [cryptographically-secure API](https://bitpay.com/api) and allows payment gateway developers to focus on payment flow/e-commerce integration rather than on the specific details of client-server interaction using the API. This SDK optionally provides the flexibility for developers to have control over important details, including the handling of private keys needed for client-server communication.
44

5-
This SDK implements BitPay's remote client authentication and authorization strategy. No private or shared-secret information is ever transmitted over the wire.
5+
It also implements BitPay's remote client authentication and authorization strategy. No private or shared-secret information is ever transmitted over the wire.
66

77
### Dependencies
88

@@ -15,126 +15,113 @@ If you need testnet bitcoin please visit a testnet faucet, e.g. https://testnet.
1515

1616
For more information about testing, please see https://bitpay.com/docs/testing
1717

18+
### Handling your client private key
1819

19-
### Usage
20+
Each client paired with the BitPay server requires a ECDSA key. This key provides the security mechanism for all client interaction with the BitPay server. The public key is used to derive the specific client identity that is displayed on your BitPay dashboard. The public key is also used for securely signing all API requests from the client. See the [BitPay API](https://bitpay.com/api) for more information.
2021

21-
This library was built and tested using the Eclipse IDE; the source code tree is directly compatible with Eclipse.
22-
Library dependencies can be downloaded by executing the following command at the root of the library:
23-
24-
```
25-
mvn clean dependency:copy-dependencies -DoutputDirectory=./lib
26-
```
22+
The private key should be stored in the client environment such that it cannot be compromised. If your private key is compromised you should revoke the compromised client identity from the BitPay server and re-pair your client, see the [API tokens](https://bitpay.com/api-tokens) for more information.
2723

28-
### Handling your client private key
24+
On a Windows machine:
2925

30-
Each client paired with the BitPay server requires a public and private key. This provides the security mechanism for all client interaction with the BitPay server. The public key is used to derive the specific client identity that is displayed on your BitPay dashboard. The public key is also used for securely signing all API requests from the client. See the [BitPay API](https://bitpay.com/api) for more information.
26+
The [BitPay.Net Setup utility](https://github.com/bitpay/csharp-bitpay-client/releases/download/v2.0.1904/BitPay.Net_Setup_utility.zip) helps to generate the private key, as well as a environment file formatted in JSON which contains all configuration requirements, that should be stored in the client local file system. It is not recommended to transmit the private key over any public or unsecure networks.
3127

32-
The private key should be stored in the client environment such that it cannot be compromised. If your private key is compromised you should revoke the compromised client identity from the BitPay server and re-pair your client, see the [API tokens](https://bitpay.com/api-tokens) for more information.
28+
Follow the guide [BitPay.Net Setup utility guide](https://github.com/bitpay/csharp-bitpay-client/blob/master/BitPaySetup/README.md) that assist you to create the environment file which you will be able to modify it, either manually or by using the BitPay.Net Setup utility, later on by asking you to provide the path to your existing JSON file.
3329

34-
This SDK provides the capability of internally storing the private key on the client local file system. If the local file system is secure then this is a good option. It is also possible to generate the key yourself (using the SDK) and store the key as required. It is not recommended to transmit the private key over any public or unsecured networks.
30+
The environment file can be either generated by the BitPay.Net Setup utility or created manually by copying the following Json structure:
3531

36-
```java
37-
// Let the SDK store the private key on the clients local file system.
38-
BitPay bitpay = new BitPay();
32+
```json
33+
{
34+
"BitPayConfiguration": {
35+
"Environment": "",
36+
"EnvConfig": {
37+
"Test": {
38+
"PrivateKeyPath": "",
39+
"ApiTokens": {
40+
"pos": "",
41+
"merchant": "",
42+
"payroll": ""
43+
}
44+
},
45+
"Prod": {
46+
"PrivateKeyPath": "",
47+
"ApiTokens": {
48+
"pos": "",
49+
"merchant": "",
50+
"payroll": ""
51+
}
52+
}
53+
}
54+
}
55+
}
3956
```
4057

41-
```java
42-
// Create the private key using the SDK, store it as required, and inject the private key into the SDK.
43-
ECKey key = KeyUtils.createEcKey();
44-
this.bitpay = new BitPay(key);
45-
```
4658

47-
```java
48-
// Create the private key external to the SDK, store it in a file, and inject the private key into the SDK.
49-
String privateKey = KeyUtils.getKeyStringFromFile(privateKeyFile);
50-
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey);
51-
this.bitpay = new BitPay(key);
52-
```
59+
### Usage
5360

54-
### Pair your client with BitPay
61+
This library was built and tested using the Intellij IDE; the source code tree is directly compatible with Other Java IDEs.
62+
Library dependencies can be downloaded by executing the following command at the root of the library:
5563

56-
Your client must be paired with the BitPay server. The pairing initializes authentication and authorization for your client to communicate with BitPay for your specific merchant account. There are two pairing modes available; client initiated and server initiated.
64+
You can also look ar the full JavaDoc for reference [here](http://htmlpreview.github.io/?https://github.com/bitpay/java-bitpay-client/blob/master/doc/index.html)
5765

58-
#### Client initiated pairing
66+
### Initializing your BitPay client
5967

60-
Pairing is accomplished by having your client request a pairing code from the BitPay server. The pairing code is then entered into the BitPay merchant dashboard for the desired merchant. Your interactive authentication at https://bitpay.com/login provides the authentication needed to create finalize the client-server pairing request.
68+
Once you have the environment file (JSON previously generated) you can initialize the client on two different ways:
6169

62-
```java
63-
String clientName = "server 1";
64-
BitPay bitpay = new BitPay(clientName);
65-
66-
if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS))
67-
{
68-
// Get POS facade authorization code.
69-
String pairingCode = bitpay.requestClientAuthorization(BitPay.FACADE_POS);
70-
71-
// Signal the device operator that this client needs to be paired with a merchant account.
72-
System.out.print("Info: Pair this client with your merchant account using the pairing code: " + pairingCode);
73-
throw new BitPayException("Error: client is not authorized for POS facade.");
74-
}
70+
```Java
71+
// Provide the full path to the env file which you have previously stored securely.
72+
73+
Client bitpay = new Client("[FULL_PATH_TO_THE_PRIVATE_KEY]");
7574
```
7675

77-
#### Server initiated pairing
76+
```Java
77+
// Initialize with separate variables.
78+
79+
Client bitpay = new Client(
80+
Env.Test,
81+
"[FULL_PATH_TO_THE_PRIVATE_KEY]",
82+
new Env.Tokens(){{
83+
pos = "AvJdGrEqTW9HVsJit9zabAnrJabqaQDhWHRacHYgfgxK";
84+
merchant = "2smKkjA1ACPKWUGN7wUEEqdWi3rhXYhDX6AKgG4njKvj";
85+
payroll = "9pJ7fzW1GGeuDQfj32aNATCDnyY6YAacVMcDrs7HHUNo";
86+
}}
87+
);
88+
```
7889

79-
Pairing is accomplished by obtaining a pairing code from the BitPay server. The pairing code is then injected into your client (typically during client initialization/configuration). Your interactive authentication at https://bitpay.com/login provides the authentication needed to create finalize the client-server pairing request.
90+
### Pair your client with BitPay
8091

81-
```java
82-
// Obtain a pairingCode from your BitPay account administrator.
83-
String pairingCode = "xxxxxxx";
84-
String clientName = "server 1";
85-
BitPay bitpay = new BitPay(clientName);
92+
Your client must be paired with the BitPay server. The pairing initializes authentication and authorization for your client to communicate with BitPay for your specific merchant account.
8693

87-
// Is this client already authorized to use the POS facade?
88-
if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS))
89-
{
90-
// Get POS facade authorization.
91-
bitpay.authorizeClient(pairingCode);
92-
}
93-
```
94+
Pairing is accomplished by having the BitPay.Net Setup utility request a pairing code from the BitPay server.
95+
Meanwhile a new pairing code is generated, the BitPay.Net Setup utility will ask you to activate it in your BitPay account. It will also store the paired token in the environment file.
96+
97+
The pairing code is then entered into the BitPay merchant dashboard for the desired merchant. Your interactive authentication at https://bitpay.com/login provides the authentication needed to create finalize the client-server pairing request.
9498

9599
### Create an invoice
96100

97101
```java
98-
Invoice invoice = bitpay.createInvoice(100, "USD");
102+
Invoice invoice = bitpay.createInvoice(new Invoice(50.0, "USD"));
99103

100104
String invoiceUrl = invoice.getURL();
101105

102106
String status = invoice.getStatus();
103107
```
104108

105-
### Create an invoice (extended)
106-
107-
You can add optional attributes to the invoice. Attributes that are not set are ignored or given default values. For example:
108-
109-
```java
110-
InvoiceBuyer buyer = new InvoiceBuyer();
111-
buyer.setName("Satoshi");
112-
buyer.setEmail("[email protected]");
113-
114-
Invoice invoice = new Invoice(100.0, "USD");
115-
invoice.setBuyer(buyer);
116-
invoice.setFullNotifications(true);
117-
invoice.setNotificationEmail("[email protected]");
118-
invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
119-
120-
invoice = this.bitpay.createInvoice(invoice);
121-
```
122-
123-
### Retreive an invoice
109+
### Retrieve an invoice
124110

125111
```java
126-
invoice = bitpay.getInvoice(invoice.getId());
112+
Invoice invoice = bitpay.getInvoice(invoice.getId());
127113
```
128114

129115
### Get exchange Rates
130116

131-
You can retrieve BitPay's [BBB exchange rates](https://bitpay.com/bitcoin-exchange-rates):
117+
You can retrieve BitPay's [BBB exchange rates](https://bitpay.com/exchange-rates).
132118

133119
```java
134-
Rates rates = this.bitpay.getRates();
120+
Rates rates = bitpay.getRates();
135121

136122
double rate = rates.getRate("USD");
137123

138124
rates.update();
139125
```
126+
See also the test package for more examples of API calls.
140127

README.md

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,28 @@
1-
java-bitpay-client
2-
==================
1+
<img src="https://bitpay.com/_nuxt/img/1c0494b.svg" width="150">
32

4-
This is the Java client library for the BitPay Payment Gateway. This library implements BitPay's [Cryptographically Secure RESTful API](https://bitpay.com/api).
3+
# BitPay Java client
4+
[![License](https://img.shields.io/github/license/bitpay/java-bitpay-client.svg?style=for-the-badge&logo=github)](https://raw.githubusercontent.com/bitpay/java-bitpay-client/master/LICENSE)
55

6-
## Quick Start Guide
6+
Full implementation of the BitPay Payment Gateway. This library implements BitPay's [Cryptographically Secure RESTful API](https://bitpay.com/api).
77

8-
To get up and running with our Java library quickly, see the GUIDE here: https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md
8+
## Getting Started
99

10-
## Eclipse Project Setup
11-
12-
1. Import the project from git repository.
13-
14-
```
15-
From Project Explorer > Import > Projects from Git ...
16-
```
17-
18-
2. Convert project to a Java project - locate and edit the .project file in your Eclipse workspace directory to include the following.
19-
20-
```xml
21-
<buildSpec>
22-
<buildCommand>
23-
<name>org.eclipse.jdt.core.javabuilder</name>
24-
<arguments>
25-
</arguments>
26-
</buildCommand>
27-
</buildSpec>
28-
<natures>
29-
<nature>org.eclipse.jdt.core.javanature</nature>
30-
</natures>
31-
```
32-
33-
3. Download project dependencies using maven.
34-
35-
```
36-
cd <root directory of project>
37-
mvn dependency:copy-dependencies -DoutputDirectory=lib
38-
```
39-
40-
4. Add dependencies - add external JAR files downloaded by maven to the Eclipse project.
41-
42-
```
43-
Project > Properties > Java Build Path > Libraries > Add External JARs > (choose all JARs in lib directory)
44-
```
45-
46-
5. Add JUnit Library to the project.
47-
48-
```
49-
Project > Properties > Java Build Path > Libraries > Add Library > Unit > Unit 4
50-
```
51-
52-
6. Run tests.
53-
54-
```
55-
src/test/BitPayTest.java > Run As > JUnit Test
56-
```
10+
To get up and running with our C# library quickly, follow [The GUIDE](https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md)
5711

5812
## Support
5913

6014
* https://github.com/bitpay/java-bitpay-client/issues
61-
* https://help.bitpay.com/
15+
* https://support.bitpay.com
6216

6317
## Contribute
6418

6519
To contribute to this project, please fork and submit a pull request.
6620

6721
## License
6822

69-
The MIT License (MIT)
23+
MIT License
7024

71-
Copyright (c) 2014-2018 BitPay, Inc.
25+
Copyright (c) 2019 BitPay
7226

7327
Permission is hereby granted, free of charge, to any person obtaining a copy
7428
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)