balanced / balanced-dashboard

The Balanced dashboard.
https://dashboard.balancedpayments.com/
Other
2.28k stars 386 forks source link

Hide the reverse button on a credit for debit cards #1478

Closed trenton42 closed 10 years ago

trenton42 commented 10 years ago

Closes balanced/balanced-dashboard#1477

msherry commented 10 years ago

This seems like it should be controlled via the API, rather than logic in the dashboard. The API knows its capabilities better than anything else.

trenton42 commented 10 years ago

@msherry I wasn't sure about that. I only added it to the existing logic because it already checks if the credit failed or if the reversible amount is greater than zero.

mahmoudimus commented 10 years ago

@trenton42 this is awesome :) Thank you for contributing code! This makes me super happy!

trenton42 commented 10 years ago

@mahmoudimus It's not much, but hopefully we can contribute more in the future!

coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling 336a9e2b0b478d1b624c56f56b4c4382ee3474e9 on trenton42:hide-reverse-button-for-debit into 182d940d0eab61883094bc084e3d35f6831e32cb on balanced:master.

mjallday commented 10 years ago

This seems like it should be controlled via the API, rather than logic in the dashboard. The API knows its capabilities better than anything else.

I think @msherry is correct. The better way to implement this fix is to check for the presence of a reversals collection on the funding instrument.

I looked at the FundingInstrument model in the app and it doesn't seem to have any properties to make this easy however. IMO I should be able to write if (funding_instrument.reversals) { /* I can assume that because of this property I can access reversals*/ }. Given that this does not exist we should merge this patch but open a subsequent issue to make the models easier to work with. They should have properties I can inspect to find out what operations the instruct accepts.

If I GET a card from the API:

curl https://api.balancedpayments.com/cards/CC4B2H8ApAiCrIqvfLJcjlpr \
     -H "Accept: application/vnd.api+json;revision=1.1" \
     -u ak-test-2KyZLwTSMm3yhgbLxU6lWFSMoJd4bGLq:

I get the following response (I've removed the body of majority of the response for clarity):

{
    "cards": [
        {
            "href": "/cards/CC4B2H8ApAiCrIqvfLJcjlpr", 
            "id": "CC4B2H8ApAiCrIqvfLJcjlpr",
            "links": {
                "customer": null
            }, 
            "type": "credit"
        }
    ], 
    "links": {
        "cards.card_holds": "/cards/{cards.id}/card_holds", 
        "cards.customer": "/customers/{cards.customer}", 
        "cards.debits": "/cards/{cards.id}/debits", 
        "cards.disputes": "/cards/{cards.id}/disputes"
    }
}

I believe the correct way to resolve this issue would be to look at the links collection for a "*.reversals" collection. If that existed then we could infer that the card has a collection of reversals and that they could be created by POSTing to that endpoint.

I do note however that if you were returning a collection of cards and one out of the collection supported reversals then the link would appear in the collection but there would be no way of telling which card supported reversals.