webhooks: Properly format the currency amount for refunds.

By default all Stripe API amounts are in the currency's smallest unit.
It's upto us to convert it to a bigger unit and show it to the end user.
And refund event used to show the currency in the smallest unit which makes
the output wrong when it comes to most currencies like USD, Europ, INR etc
which uses a bigger unit(eg Dollar instead of Cents) as the standard.
This commit is contained in:
Vishnu KS 2020-11-25 16:47:08 +05:30 committed by Tim Abbott
parent b559da68bf
commit dabbc3445a
2 changed files with 4 additions and 5 deletions

View File

@ -208,12 +208,12 @@ Amount due: 0.00 INR
def test_refund_event(self) -> None:
expected_topic = "refunds"
expected_message = "A [refund](https://dashboard.stripe.com/refunds/re_1Gib6ZHLwdCOCoR7VrzCnXlj) for a [charge](https://dashboard.stripe.com/charges/ch_1Gib61HLwdCOCoR71rnkccye) of 30000000 INR was updated."
expected_message = "A [refund](https://dashboard.stripe.com/refunds/re_1Gib6ZHLwdCOCoR7VrzCnXlj) for a [charge](https://dashboard.stripe.com/charges/ch_1Gib61HLwdCOCoR71rnkccye) of 300000.00 INR was updated."
self.check_webhook("refund_event", expected_topic, expected_message)
def test_pseudo_refund_event(self) -> None:
expected_topic = "refunds"
expected_message = "A [refund](https://dashboard.stripe.com/refunds/pyr_abcde12345ABCDF) for a [payment](https://dashboard.stripe.com/payments/py_abcde12345ABCDG) of 1234 EUR was updated."
expected_message = "A [refund](https://dashboard.stripe.com/refunds/pyr_abcde12345ABCDF) for a [payment](https://dashboard.stripe.com/payments/py_abcde12345ABCDG) of 12.34 EUR was updated."
self.check_webhook("pseudo_refund_event", expected_topic, expected_message)
@patch('zerver.webhooks.stripe.view.check_send_webhook_message')

View File

@ -99,11 +99,10 @@ def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]:
status=object_['status'].replace('_', ' '))
if resource == 'refund':
topic = 'refunds'
body = 'A {resource} for a {charge} of {amount} {currency} was updated.'.format(
body = 'A {resource} for a {charge} of {amount} was updated.'.format(
resource=linkified_id(object_['id'], lower=True),
charge=linkified_id(object_['charge'], lower=True),
amount=object_['amount'],
currency=object_['currency'].upper(),
amount=amount_string(object_['amount'], object_['currency']),
)
if category == 'checkout_beta': # nocoverage
# Not sure what this is