Skip to content

getInvoice Doesn't Use Public Facade #10

Closed

Description

@jmswenski

It seems that if you call getInvoice, it doesn't use the public facade. This is somewhat annoying because not all of the authenticated facades can call this endpoint.

    /**
     * Retrieve a BitPay invoice by invoice id using the public facade.
     * @param invoiceId The id of the invoice to retrieve.
     * @return A BitPay Invoice object.
     * @throws BitPayException
     */
    public Invoice getInvoice(String invoiceId) throws BitPayException
    {
        return this.getInvoice(invoiceId, PUBLIC_NO_TOKEN);
    }

This in turns calls one of the private get() methods which doesn't do anything particular at all about trying to use the public facade. It happily uses the current facade and signs the request.

private HttpResponse get(String uri, Hashtable parameters) throws BitPayException
    {
        try {

            String fullURL = _baseUrl + uri;
            HttpGet get = new HttpGet(fullURL);

            if (parameters != null) {
                fullURL += "?";

                for (String key : parameters.keySet()) {
                    fullURL += key + "=" + parameters.get(key) + "&";
                }

                fullURL = fullURL.substring(0,fullURL.length() - 1);

                get.setURI(new URI(fullURL));

                String signature = KeyUtils.sign(_ecKey, fullURL);

                get.addHeader("x-bitpay-plugin-info", BITPAY_PLUGIN_INFO);
                get.addHeader("x-accept-version", BITPAY_API_VERSION);
                get.addHeader("x-signature", signature);
                get.addHeader("x-identity", KeyUtils.bytesToHex(_ecKey.getPubKey()));
            }

I'm submitting a pull request that changes this by adding a method that allows for being explicit about if you want to sign the request (modeling it somewhat after the way one of the post methods was designed)

I've also taken the liberty of cleaning up how some of the URL parameters are built. A complete solution would have used URI builder since the project includes httpclient. I have not done this yet, but will in a future PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions