coinbase / coinbase-java

Coinbase API v1 library for Java
Apache License 2.0
149 stars 98 forks source link

Commerce support? #59

Closed eepstein closed 6 years ago

eepstein commented 6 years ago

I'm looking for commerce support in Java.

The official docs are kinda sparse - no formal definition of the payload, no information on what is expected to be returned, etc.

Is a Java SDK planned?

smilanko commented 6 years ago

What exactly are you attempting to do?

On Apr 21, 2018, at 12:46 AM, Ezra Epstein notifications@github.com wrote:

I'm looking for commerce support in Java.

The official docs are kinda sparse - no formal definition of the payload, no information on what is expected to be returned, etc.

Is a Java SDK planned?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

eepstein commented 6 years ago

Two things: 1) building a webhook handler. So far it's going fine, but I'm having to guess a fair bit along the way. (That said, I've got the full model now in POJOs and that seems to work ok.) Does coinbase expect a response and retries a few times until it gets an "OK" response, or does it fire and forget it? Are their instructions for doing the hashing of the body to check the header value? E.g., does one need to pad the text or anything?

Finally, (and separately) we're making custom Charge objects via the Coinbase Commerce API but it doesn't seem to allow us to set an image to use. Any help on that front or should I open a separate ticket? Checkouts don't work for us because we need to record the user's invoice# as metadata and checkouts only support "name" and "email" and require the user to fill those in, whereas we auto-populate the invoice metadata value on the Charge we create.

eepstein commented 6 years ago

Mostly looking for help with the second item now - basically a more flexible UI than what's baked into the checkout/charge flows. In particular a way to pass additional info into a charge created from a checkout OR to include a custom image in a charge created via the API either one would work

eepstein commented 6 years ago

On the first item, code's:

private static final String SIGNING_ALGORITHM = "HmacSHA256";
private static final Charset UTF8 = Charset.forName("UTF8");

private final ObjectMapper objectMapper;

private final Mac sha256Hmac;
private final SecretKeySpec secretKey;
private final BaseEncoding signatureEncoding;

@Autowired
public CoinbaseController(ObjectMapper objectMapper, AppConfig appConfig)
        throws NoSuchAlgorithmException, InvalidKeyException {
    this.objectMapper = objectMapper;
    this.sha256Hmac = Mac.getInstance(SIGNING_ALGORITHM);
    this.secretKey = new SecretKeySpec(appConfig.getCoinbase().getSharedSecret().getBytes(UTF8),
                                       SIGNING_ALGORITHM);
    sha256Hmac.init(secretKey);
    this.signatureEncoding = BaseEncoding.base16().lowerCase().omitPadding();
}

private String computeHmacSha256Signature(String message) {
    String nullSafeMessage = (message == null) ? "" : message;
    return signatureEncoding.encode(sha256Hmac.doFinal(nullSafeMessage.getBytes(UTF8)));
}

and is working fine

eepstein commented 6 years ago

also, the docs say nothing about how often webhooks get repeated, but via testing I see that they recur every minute (not sure for how long) until a 200 OK response is given.