-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GrabPay details to the view transaction page (#10377)
- Loading branch information
1 parent
1957d7a
commit eec6b23
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Add GrabPay payment method details to the View Transaction page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import React from 'react'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import Detail from '../detail'; | ||
import { PaymentMethodDetails } from 'wcpay/payment-details/types'; | ||
import { Charge } from 'wcpay/types/charges'; | ||
|
||
/** | ||
* Extracts and formats payment method details from a charge. | ||
* | ||
* @param {Charge} charge The charge object. | ||
* @return {PaymentMethodDetails} A flat hash of all necessary values. | ||
*/ | ||
const formatPaymentMethodDetails = ( charge: Charge ): PaymentMethodDetails => { | ||
const { billing_details: billingDetails, payment_method: id } = charge; | ||
const { name, email, formatted_address: formattedAddress } = billingDetails; | ||
|
||
return { | ||
id, | ||
name, | ||
email, | ||
formattedAddress, | ||
}; | ||
}; | ||
|
||
interface GrabPayDetailsProps { | ||
charge: Charge; | ||
isLoading: boolean; | ||
} | ||
|
||
const GrabPayDetails: React.FC< GrabPayDetailsProps > = ( { | ||
charge, | ||
isLoading, | ||
} ) => { | ||
const { id, name, email, formattedAddress } = formatPaymentMethodDetails( | ||
charge | ||
); | ||
|
||
return ( | ||
<div className="payment-method-details"> | ||
<div className="payment-method-details__column"> | ||
<Detail | ||
isLoading={ isLoading } | ||
label={ __( 'ID', 'woocommerce-payments' ) } | ||
> | ||
{ !! id ? id : '–' } | ||
</Detail> | ||
</div> | ||
|
||
<div className="payment-method-details__column"> | ||
<Detail | ||
isLoading={ isLoading } | ||
label={ __( 'Owner', 'woocommerce-payments' ) } | ||
> | ||
{ name || '–' } | ||
</Detail> | ||
|
||
<Detail | ||
isLoading={ isLoading } | ||
label={ __( 'Owner email', 'woocommerce-payments' ) } | ||
> | ||
{ email || '–' } | ||
</Detail> | ||
|
||
<Detail | ||
isLoading={ isLoading } | ||
label={ __( 'Address', 'woocommerce-payments' ) } | ||
> | ||
<span | ||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={ { | ||
__html: formattedAddress || '–', | ||
} } | ||
/> | ||
</Detail> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GrabPayDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters