Skip to content

Commit

Permalink
fix(Receipt): adapt for refunds (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree authored Sep 4, 2024
1 parent a2e53a8 commit 47f0fb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
20 changes: 12 additions & 8 deletions components/Receipt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage, injectIntl } from 'react-intl';
import { FormattedMessage } from 'react-intl';
import { get, chunk, sumBy, max, isNil, round, uniqBy } from 'lodash';
import { Box, Flex } from './styled-components/Grid';
import moment from 'moment';
Expand Down Expand Up @@ -36,6 +36,7 @@ export class Receipt extends React.Component {
static propTypes = {
/** The receipt data */
receipt: PropTypes.shape({
isRefundOnly: PropTypes.bool,
dateFrom: PropTypes.string,
dateTo: PropTypes.string,
currency: PropTypes.string.isRequired,
Expand Down Expand Up @@ -94,9 +95,6 @@ export class Receipt extends React.Component {
* document.
*/
debug: PropTypes.bool,
/** CSS zoom applied */
zoom: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
intl: PropTypes.object.isRequired, // from withIntl
};

static defaultProps = {
Expand Down Expand Up @@ -387,7 +385,11 @@ export class Receipt extends React.Component {
</Box>
<Box mt={80} pr={3} css={{ minHeight: 100 }}>
<H2 fontSize="16px" lineHeight="18px">
<FormattedMessage id="billTo" defaultMessage="Bill to" />
{receipt.isRefundOnly ? (
<FormattedMessage id="refundTo" defaultMessage="Refund to" />
) : (
<FormattedMessage id="billTo" defaultMessage="Bill to" />
)}
</H2>
<Box my={2}>
<P fontWeight={500} fontSize="13px">
Expand All @@ -402,7 +404,9 @@ export class Receipt extends React.Component {
<Flex justifyContent="space-between">
<Box>
<H2 fontSize="16px" lineHeight="18px">
{receipt.template?.title || (
{receipt.template?.title || receipt.isRefundOnly ? (
<FormattedMessage defaultMessage="Payment refund" />
) : (
<FormattedMessage id="invoice.donationReceipt" defaultMessage="Payment Receipt" />
)}
</H2>
Expand Down Expand Up @@ -499,7 +503,7 @@ export class Receipt extends React.Component {
<Flex flex="3" flexDirection="column" justifyContent="space-between">
<Box>
<P fontSize="11px" textAlign="left" whiteSpace="pre-wrap">
{receipt?.template?.info}
{receipt.template?.info}
</P>
</Box>
<CollectiveFooter collective={receipt.host} />
Expand All @@ -513,4 +517,4 @@ export class Receipt extends React.Component {
}
}

export default injectIntl(Receipt);
export default Receipt;
17 changes: 8 additions & 9 deletions lib/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const receiptTransactionFragment = gql`
description
hostCurrencyFxRate
invoiceTemplate
isRefund
host {
...ReceiptTransactionHostFieldsFragment
}
Expand Down Expand Up @@ -59,6 +60,12 @@ const receiptTransactionFragment = gql`
rate
}
type
paymentMethod {
id
type
service
name
}
fromAccount {
id
slug
Expand Down Expand Up @@ -218,15 +225,7 @@ export async function fetchTransactionInvoice(transactionId, authorizationHeader
permissions {
canDownloadInvoice
}
paymentMethod {
id
type
service
name
}
... on Credit {
...ReceiptTransactionFragment
}
...ReceiptTransactionFragment
... on Debit {
oppositeTransaction {
...ReceiptTransactionFragment
Expand Down
11 changes: 7 additions & 4 deletions pages/receipts/transactions/[id]/[filename].js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class TransactionReceipt extends React.Component {
return { pageFormat: ctx.query?.pageFormat };
}

static getReceiptFromData(transaction) {
if (transaction.type === 'DEBIT' && transaction.oppositeTransaction) {
static getReceiptFromData(originalTransaction) {
let transaction = originalTransaction;
if (transaction.type === 'DEBIT' && transaction.oppositeTransaction && !transaction.isRefund) {
transaction = transaction.oppositeTransaction;
}

Expand All @@ -38,13 +39,15 @@ class TransactionReceipt extends React.Component {

const invoiceName = transaction.invoiceTemplate || transaction.order?.tier?.invoiceTemplate;
const template = host.settings?.invoice?.templates?.[invoiceName] || host?.settings?.invoice?.templates?.default;
const fromAccount = transaction.isRefund ? transaction.toAccount : transaction.fromAccount;
return {
isRefundOnly: transaction.isRefund,
currency: transaction.amountInHostCurrency.currency,
totalAmount: transaction.amountInHostCurrency.valueInCents,
transactions: [transaction],
host,
fromAccount: transaction.fromAccount,
fromAccountHost: transaction.fromAccount.host,
fromAccount: fromAccount,
fromAccountHost: fromAccount.host,
template,
};
}
Expand Down

0 comments on commit 47f0fb0

Please sign in to comment.