Skip to content

Commit 1e048be

Browse files
author
Andy Phillipson
committed
Updated to reflect the current implementation.
1 parent 2f05c63 commit 1e048be

File tree

1 file changed

+77
-21
lines changed

1 file changed

+77
-21
lines changed

README.md

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,82 @@
11
java-bitpay-client
22
==================
33

4-
This is the Java client library for the BitPay Payment Gateway. This library implements BitPay's new cryptographically-secure API.
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).
55

66
Dependencies
77
------------
8-
BitPay merchant account
8+
You must have a BitPay merchant account to use this SDK. It's free to [sign-up for a BitPay merchant account](https://bitpay.com/start).
99

10-
ApacheHttpClient
10+
Getting Started
11+
---------------
1112

12-
java-json
13+
This SDK provides a convenient abstration 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.
1314

14-
json-simple
15+
This SDK implements BitPay's remote client authentication and authorization strategy. No private or shared-secret information is ever transmitted over the wire.
1516

16-
Getting Started
17-
---------------
17+
####Handling your client private key
18+
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.
19+
20+
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.
1821

19-
Log into your BitPay merchant account and generate a Private Key. Then all you need to do is instantiate a BitPay object, and pass in your private key.
22+
This Java 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 unsecure networks.
2023

2124
```java
22-
String privateKey = KeyUtils.readBitcoreKeyFromFile(privateKeyFile);
23-
ECKey key = KeyUtils.loadKey(privateKey);
25+
// Let the SDK store the private key on the clients local file system.
26+
BitPay bitpay = new BitPay();
27+
```
28+
29+
```java
30+
// Create the private key using the SDK, store it as required, and inject the private key into the SDK.
31+
ECKey key = KeyUtils.createEcKey();
2432
this.bitpay = new BitPay(key);
2533
```
2634

35+
```java
36+
// Create the private key external to the SDK, store it in a file, and inject the private key into the SDK.
37+
String privateKey = KeyUtils.getKeyStringFromFile(privateKeyFile);
38+
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey);
39+
this.bitpay = new BitPay(key);
40+
```
41+
42+
####Pair your client with BitPay
43+
Your Java 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.
44+
45+
#####Client initiated pairing
46+
Pairing is accomplished by having your Java 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.
47+
48+
```java
49+
String clientName = "server 1";
50+
BitPay bitpay = new BitPay(clientName);
51+
52+
if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS))
53+
{
54+
// Get POS facade authorization code.
55+
String pairingCode = bitpay.requestClientAuthorization(BitPay.FACADE_POS);
56+
57+
// Signal the device operator that this client needs to be paired with a merchant account.
58+
System.out.print("Info: Pair this client with your merchant account using the pairing code: " + pairingCode);
59+
throw new BitPayException("Error: client is not authorized for POS facade.");
60+
}
61+
```
62+
63+
#####Server initiated pairing
64+
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.
65+
66+
```java
67+
// Obtain a pairingCode from your BitPay account administrator.
68+
String pairingCode = "xxxxxxx";
69+
String clientName = "server 1";
70+
BitPay bitpay = new BitPay(clientName);
71+
72+
// Is this client already authorized to use the POS facade?
73+
if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS))
74+
{
75+
// Get POS facade authorization.
76+
bitpay.authorizeClient(pairingCode);
77+
}
78+
```
79+
2780
####Create an invoice
2881
```java
2982
Invoice invoice = bitpay.createInvoice(100, "USD");
@@ -39,7 +92,7 @@ invoice = bitpay.getInvoice(invoice.getId());
3992
```
4093
####Exchange Rates
4194

42-
You can also get BitPay's exchange rates.
95+
You can retrieve BitPay's [BBB exchange rates](https://bitpay.com/bitcoin-exchange-rates).
4396
```java
4497
Rates rates = this.bitpay.getRates();
4598

@@ -49,16 +102,19 @@ rates.update();
49102
```
50103
####Advanced Invoices
51104

52-
You can add additional params to the invoice by passing an InvoiceParams object. You don't have to set all of the advanced parameters. It will only use the ones you do set.
105+
You can add optional attributes to the invoice. Atributes that are not set are ignored or given default values.
53106
```java
54-
InvoiceParams params = new InvoiceParams();
55-
56-
params.setBuyerName("Satoshi");
57-
params.setBuyerEmail("[email protected]");
58-
params.setFullNotifications(true);
59-
params.setNotificationEmail("[email protected]");
60-
61-
Invoice invoice = this.bitpay.createInvoice(100, "USD", params);
107+
InvoiceBuyer buyer = new InvoiceBuyer();
108+
buyer.setName("Satoshi");
109+
buyer.setEmail("[email protected]");
110+
111+
Invoice invoice = new Invoice(100.0, "USD");
112+
invoice.setBuyer(buyer);
113+
invoice.setFullNotifications(true);
114+
invoice.setNotificationEmail("[email protected]");
115+
invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
116+
117+
invoice = this.bitpay.createInvoice(invoice);
62118
```
63119

64120
# Support
@@ -70,7 +126,7 @@ Invoice invoice = this.bitpay.createInvoice(100, "USD", params);
70126

71127
The MIT License (MIT)
72128

73-
Copyright (c) 2014 BitPay, Inc.
129+
Copyright (c) 2014-2015 BitPay, Inc.
74130

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

0 commit comments

Comments
 (0)