Skip to content

InvoiceTransaction needs exRates field #20

Closed

Description

@MaDeRkAn

When we call requestRefund, server returns exRates field "exRates":{"USD":882.03}} But InvoiceTransaction doesn't include this field and that's why it throws exception on mapping.

Activity

  1. pieterpoorthuis commented on Jan 17, 2017

    @pieterpoorthuis

    I'll check and fix

  2. MaDeRkAn commented on Jan 17, 2017

    @MaDeRkAn
    Author

    This happens if you get invoice with merchant facade. Second error which is related: If you send refund request with amount and currency and if the invoice is partially paid, server returns 500.

    "message": "Error: do not specify amount or currency for refunds of partially paid invoices"

    There is no way to refund partially paid invoice with current implementation.

  3. MaDeRkAn commented on Jan 18, 2017

    @MaDeRkAn
    Author
    1. Add exrates field to InvoiceTransaction

    2. Assign amount and currency only if invoice is fully paid.

    I have added private method isFullyPaid and change requestRefund method.

    Here is the code:

        public RefundHelper requestRefund(Invoice invoice, String bitcoinAddress, Double amount, String currency) throws BitPayException {
            if (bitcoinAddress == null && !invoice.getFlags().getRefundable()) {
                throw new BitPayException("Error - cannot refund an invoice without a refund address");
            }
    
            Refund refund = new Refund();
    
            if(isFullyPaid(invoice))
            {
                refund.setAmount(amount);
                refund.setCurrency(currency);
            }
    
            refund.setToken(invoice.getToken());
            refund.setGuid(this.getGuid());
            refund.setBitcoinAddress(bitcoinAddress);
    
            ObjectMapper mapper = new ObjectMapper();
    
            String json;
    
            try {
                json = mapper.writeValueAsString(refund);
            } catch (JsonProcessingException e) {
                throw new BitPayException("Error - failed to serialize Refund object : " + e.getMessage());
            }
    
            HttpResponse response = this.postWithSignature("invoices/" + invoice.getId() + "/refunds", json);
    
            try {
                refund = mapper.readerForUpdating(refund).readValue(this.responseToJsonString(response));
            } catch (JsonProcessingException e) {
                throw new BitPayException("Error - failed to deserialize BitPay server response (Refund) : " + e.getMessage());
            } catch (IOException e) {
                throw new BitPayException("Error - failed to deserialize BitPay server response (Refund) : " + e.getMessage());
            }
    
            this.cacheAccessToken(refund.getId(), refund.getToken());
            return new RefundHelper(refund, invoice);
        }
    
        private boolean isFullyPaid(Invoice invoice) {
            Double btcPaid = Double.valueOf(invoice.getBtcPaid());
            Double btcAmount = Double.valueOf(invoice.getBtcPrice());
    
            return btcAmount.equals(btcPaid);
        }
    
  4. ajp8164 commented on Jan 19, 2017

    @ajp8164

    I believe if you request a refund on a partially paid invoice you should NOT specify amount or currency. Rule is to refund 100% of partial paid invoices and only in BTC since tx did not hit merchant ledger.

  5. MaDeRkAn commented on Jan 20, 2017

    @MaDeRkAn
    Author

    @ajp8164 Exactly it's right what you say. But, there are 2 public methods for now and one is calling the other one. So api has just 1 method and it needs currency and amount. I have added logic inside of method to not break anything. But you can decide or implement another method requestPartial refund vs it's your choice :)

  6. added a commit that references this issue on Feb 3, 2017
  7. added a commit that references this issue on Feb 3, 2017
  8. pieterpoorthuis commented on Feb 3, 2017

    @pieterpoorthuis

    Reopened to also fix the refund request

  9. ajp8164 commented on May 17, 2017

    @ajp8164

    Refund can't map exRates response

  10. aniruddhamahato commented on Mar 14, 2018

    @aniruddhamahato

    I want to implement a POC of bitcoin payment using Bitpay API. Please help me to implement this.
    I m not getting anything from the client API code.
    My mail id is [email protected] .
    I m doing this for my client .If they approved it I will go with this solution only.

  11. pieterpoorthuis commented on Mar 14, 2018

    @pieterpoorthuis

    Your test account is not properly configured. Make sure to configure a settlement address. You can use the following testnet BTC address if you want: mkdb3xayMmpGaWG6fJWeA2LtbBmm3cNCjT

    More information about testing can be found here: https://bitpay.com/docs/testing

  12. aniruddhamahato commented on Mar 16, 2018

    @aniruddhamahato
  13. pieterpoorthuis commented on Mar 21, 2018

    @pieterpoorthuis

    Test BTC coins can be fetched from a testnet BTC faucet, like in https://testnet.coinfaucet.eu/en/

  14. aniruddhamahato commented on Mar 22, 2018

    @aniruddhamahato
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