Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debit class has no self.refunds_uri #70

Closed
peterbe opened this issue Nov 18, 2013 · 9 comments
Closed

Debit class has no self.refunds_uri #70

peterbe opened this issue Nov 18, 2013 · 9 comments

Comments

@peterbe
Copy link

peterbe commented Nov 18, 2013

Been looking at this class:

class Debit(Resource):
    """
    A Debit represents a transfer of funds from a buyer's Account to your
    Marketplace's escrow account.

    A Debit may be created directly, or it will be created as a side-effect
    of capturing a Hold. If you create a Debit directly it will implicitly
    create the associated Hold if the funding source supports this.

    If no Hold is specified, the Debit will by default be created using the
    most recently added funding source associated with the Account. You
    cannot change the funding source between creating a Hold and capturing
    it.
    """
    __metaclass__ = resource_base(collection='debits')

    def refund(self, amount=None, description=None, meta=None):
        """
        Refunds this Debit. If no amount is specified it will refund the entire
        amount of the Debit, you may create many Refunds up to the sum total
        of the original Debit's amount.

        :rtype: Refund
        """
        meta = meta or {}
        return Refund(
            uri=self.refunds_uri,
            debit_uri=self.uri,
            amount=amount,
            description=description,
            meta=meta,
        ).save()

But when you try to use this, you get
AttributeError: 'Debit' object has no attribute 'refunds_uri'

I tried changing self.refunds_uri to self.uri but then I got:
HTTPError: Method Not Allowed: 405: Your request id is OHM2f81d254500c11e...redacted....

@peterbe
Copy link
Author

peterbe commented Nov 18, 2013

At the moment, I'm actually unable to issue refunds so I think this is fairly important.

@mahmoudimus
Copy link
Contributor

@peterbe can you list the request id?

@peterbe
Copy link
Author

peterbe commented Nov 18, 2013

@mahmoudimus The full thing?
OHM2f81d254500c11e3bb77026ba7f8ec28

@mjallday
Copy link
Contributor

@peterbe that's the request ID for the 405. Can you get us the request ID (or the URI potentially) for the GET request to get the debit that does not have the refund uri?

When I CURL the debits for the marketplace associated with the above OHM, I can see the refunds_uri property on the debits that I get.

curl https://api.balancedpayments.com/v1/marketplaces/TEST-MP5RGqKk2k5agpbmIkN1dhR4/debits/WD5DV83HHrlwcc3kWKjdxCXg | grep refunds

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6876  100  6876    0     0  24209      0 --:--:-- --:--:-- --:--:-- 24211
    "refunds_uri": {
      "key": "refunds"
      "refunds_uri": {
        "key": "refunds"
    "refunds_uri": "/v1/customers/CU5CzdPj0X2KVv4l37KZ8dDq/refunds",
      "refunds_uri": {
        "key": "refunds"
    "refunds_uri": "/v1/marketplaces/TEST-MP5RGqKk2k5agpbmIkN1dhR4/accounts/CU5CzdPj0X2KVv4l37KZ8dDq/refunds",
  "refunds_uri": "/v1/marketplaces/TEST-MP5RGqKk2k5agpbmIkN1dhR4/debits/WD5DV83HHrlwcc3kWKjdxCXg/refunds",

Can you show us the code that you're running? I suspect that you're doing balanced.Debit.find(uri) where uri does not point to a debit but maybe another resources such as a customer.

@peterbe
Copy link
Author

peterbe commented Nov 18, 2013

This is my code:

                balanced.configure(settings.BALANCED_API_KEY)
                debit = balanced.Debit.find(payment.balanced_uri)
                description = form.cleaned_data.get('description')
                if not description:
                    description = 'Refund for %s' % payment.item.identifier
                refund_cents = int(Decimal('100') * refund_amount_after)
                print debit.refund(
                    amount=refund_cents,
                    description=description,
                    meta={
                        'payment.id': str(payment.pk),
                        'item.identifier': payment.item.identifier,
                    }
                )

That payment.balanced_uri I got from doing this:

            balanced.configure(settings.BALANCED_API_KEY)
            customer = balanced.Customer().save()
            customer.add_card(form.cleaned_data['uri'])  #<-- this is the same as `payment.balanced_uri`
            customer.debit(
                amount=amount_cents,
                appears_on_statement_as=appears_on_statement_as,
                description=description,
            )

@mjallday
Copy link
Contributor

@peterbe can you show us payment.balanced_uri?

@peterbe
Copy link
Author

peterbe commented Nov 18, 2013

/v1/marketplaces/TEST-MP5RGqKk2k5agpbmIkN1dhR4/cards/CC4XjidiymsAQQkkcW2hwse4

@mjallday
Copy link
Contributor

OK. there's our issue. that's a URI for a card, not a debit. you can find the debits associated with that card by doing

balanced.configure(settings.BALANCED_API_KEY)
card_uri = balanced.payment_uri
card = balanced.Card.find(card_uri)
card.debits  # gives you an iterator over the debits associated with this card

let us know if that helps, if you're not sure how you got that URI in the first place jump on #balanced on irc.freenode.net and we'll figure it out together.

@peterbe
Copy link
Author

peterbe commented Nov 18, 2013

Thank you!
I better go back to the drawing board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants