Skip to content

Commit

Permalink
fix: Manual capture fails in the transaction detail screen with a cus…
Browse files Browse the repository at this point in the history
…tomized order number (#10435)
  • Loading branch information
htdat authored Feb 25, 2025
1 parent 738ce6a commit 8724369
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 35 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-10395-order-number-manual-capture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Manual capture fails in the transaction detail screen with a customized order number
2 changes: 1 addition & 1 deletion client/data/payment-intents/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function* refundCharge(
charge_id: charge.id,
amount: charge.amount,
reason: reason,
order_id: charge?.order?.number,
order_id: charge?.order?.id,
},
} );

Expand Down
6 changes: 4 additions & 2 deletions client/data/payment-intents/test/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const chargeMock: Charge = {
dispute: null,
disputed: false,
order: {
number: Number( '67' ),
id: 123,
number: 'custom-67',
url: 'http://order.url',
customer_url: 'customer.url',
customer_name: '',
Expand Down Expand Up @@ -88,7 +89,8 @@ export const paymentIntentMock: PaymentIntent = {
payment_method: 'pm_mock',
status: 'requires_capture',
order: {
number: 123,
id: 123,
number: 'custom-123',
url: 'http://order.url',
customer_url: 'customer.url',
customer_name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ exports[`Order details page should match the snapshot - Charge without payment i
data-link-type="external"
href="http://wcpay.test/wp-admin/post.php?post=776&action=edit"
>
776
custom-776
</a>
</span>
</div>
Expand Down
3 changes: 2 additions & 1 deletion client/payment-details/order-details/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const chargeFromOrderMock = {
disputed: false,
outcome: null,
order: {
number: 776,
id: 776,
number: 'custom-776',
url: 'http://wcpay.test/wp-admin/post.php?post=776&action=edit',
customer_url:
'admin.php?page=wc-admin&path=/customers&filter=single_customer&customers=55',
Expand Down
10 changes: 5 additions & 5 deletions client/payment-details/summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {

const { authorization } = useAuthorization(
charge.payment_intent as string,
charge.order?.number as number,
charge.order?.id as number,
shouldFetchAuthorization
);

Expand Down Expand Up @@ -458,7 +458,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
{ ! isLoading && isFraudOutcomeReview && (
<div className="payment-details-summary__fraud-outcome-action">
<CancelAuthorizationButton
orderId={ charge.order?.number || 0 }
orderId={ charge.order?.id || 0 }
paymentIntentId={
charge.payment_intent || ''
}
Expand All @@ -484,7 +484,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {

<CaptureAuthorizationButton
buttonIsPrimary
orderId={ charge.order?.number || 0 }
orderId={ charge.order?.id || 0 }
paymentIntentId={
charge.payment_intent || ''
}
Expand Down Expand Up @@ -599,7 +599,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
charge.payment_intent,
order_id:
charge.order
?.number,
?.id,
}
);
window.location =
Expand Down Expand Up @@ -679,7 +679,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
actions={
! isFraudOutcomeReview ? (
<CaptureAuthorizationButton
orderId={ charge.order?.number || 0 }
orderId={ charge.order?.id || 0 }
paymentIntentId={
charge.payment_intent || ''
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ exports[`PaymentDetailsSummary renders a charge with subscriptions 1`] = `
data-link-type="external"
href="https://example.com/subscription/246"
>
246
custom-246
</a>
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/payment-details/summary/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe( 'PaymentDetailsSummary', () => {
if ( charge.order ) {
charge.order.subscriptions = [
{
number: 246,
number: 'custom-246',
url: 'https://example.com/subscription/246',
},
];
Expand Down
34 changes: 17 additions & 17 deletions client/transactions/list/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ exports[`Transactions list renders correctly when can filter by several currenci
data-link-type="external"
href="https://example.com/order/123"
>
123
custom-123
</a>
</td>
<td
Expand Down Expand Up @@ -749,7 +749,7 @@ exports[`Transactions list renders correctly when can filter by several currenci
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -897,7 +897,7 @@ exports[`Transactions list renders correctly when can filter by several currenci
data-link-type="external"
href="https://example.com/order/335"
>
335
custom-335
</a>
</td>
<td
Expand Down Expand Up @@ -1561,7 +1561,7 @@ exports[`Transactions list renders correctly when filtered by currency 1`] = `
data-link-type="external"
href="https://example.com/order/123"
>
123
custom-123
</a>
</td>
<td
Expand Down Expand Up @@ -1742,7 +1742,7 @@ exports[`Transactions list renders correctly when filtered by currency 1`] = `
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -1890,7 +1890,7 @@ exports[`Transactions list renders correctly when filtered by currency 1`] = `
data-link-type="external"
href="https://example.com/order/335"
>
335
custom-335
</a>
</td>
<td
Expand Down Expand Up @@ -2558,7 +2558,7 @@ exports[`Transactions list renders correctly when filtered by payout 1`] = `
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -3248,7 +3248,7 @@ exports[`Transactions list subscription column renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/123"
>
123
custom-123
</a>
</td>
<td
Expand All @@ -3258,7 +3258,7 @@ exports[`Transactions list subscription column renders correctly 1`] = `
data-link-type="external"
href="https://example.com/subscription/246"
>
246
custom-246
</a>
</td>
<td
Expand Down Expand Up @@ -3439,7 +3439,7 @@ exports[`Transactions list subscription column renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -3590,7 +3590,7 @@ exports[`Transactions list subscription column renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/335"
>
335
custom-335
</a>
</td>
<td
Expand Down Expand Up @@ -4299,7 +4299,7 @@ exports[`Transactions list when not filtered by payout renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/123"
>
123
custom-123
</a>
</td>
<td
Expand Down Expand Up @@ -4480,7 +4480,7 @@ exports[`Transactions list when not filtered by payout renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -4628,7 +4628,7 @@ exports[`Transactions list when not filtered by payout renders correctly 1`] = `
data-link-type="external"
href="https://example.com/order/335"
>
335
custom-335
</a>
</td>
<td
Expand Down Expand Up @@ -5334,7 +5334,7 @@ exports[`Transactions list when not filtered by payout renders table summary onl
data-link-type="external"
href="https://example.com/order/123"
>
123
custom-123
</a>
</td>
<td
Expand Down Expand Up @@ -5515,7 +5515,7 @@ exports[`Transactions list when not filtered by payout renders table summary onl
data-link-type="external"
href="https://example.com/order/125"
>
125
custom-125
</a>
</td>
<td
Expand Down Expand Up @@ -5663,7 +5663,7 @@ exports[`Transactions list when not filtered by payout renders table summary onl
data-link-type="external"
href="https://example.com/order/335"
>
335
custom-335
</a>
</td>
<td
Expand Down
11 changes: 7 additions & 4 deletions client/transactions/list/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const getMockTransactions: () => Transaction[] = () => [
type: 'refund',
source: 'visa',
order: {
number: 123,
id: 123,
number: 'custom-123',
url: 'https://example.com/order/123',
// eslint-disable-next-line camelcase
customer_url: 'https://example.com/customer/my-name',
Expand Down Expand Up @@ -139,7 +140,8 @@ const getMockTransactions: () => Transaction[] = () => [
type: 'charge',
source: 'mastercard',
order: {
number: 125,
id: 123,
number: 'custom-125',
url: 'https://example.com/order/125',
// eslint-disable-next-line camelcase
customer_url: 'https://example.com/customer/my-name',
Expand Down Expand Up @@ -170,7 +172,8 @@ const getMockTransactions: () => Transaction[] = () => [
type: 'charge',
source: 'visa',
order: {
number: 335,
id: 123,
number: 'custom-335',
url: 'https://example.com/order/335',
// eslint-disable-next-line camelcase
customer_url: 'https://example.com/customer/my-name',
Expand Down Expand Up @@ -424,7 +427,7 @@ describe( 'Transactions list', () => {
const mockTransactions = getMockTransactions();
mockTransactions[ 0 ].order.subscriptions = [
{
number: 246,
number: 'custom-246',
url: 'https://example.com/subscription/246',
},
];
Expand Down
10 changes: 8 additions & 2 deletions client/types/orders.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
*/

interface SubscriptionDetails {
number: number;
number: string; // Comment for OderDetails.number below applies here as well.
url: string;
}

interface OrderDetails {
number: number;
id: number;
/**
* The order number for display.
* By default, it's order ID but a plugin can customize it.
* See PHP method WC_Order::get_order_number().
*/
number: string;
url: string;
customer_url: null | string;
customer_email: null | string;
Expand Down
1 change: 1 addition & 0 deletions includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,7 @@ private function add_order_info_to_object( $order, $object ) {
*/
public function build_order_info( WC_Order $order ): array {
$order_info = [
'id' => $order->get_id(),
'number' => $order->get_order_number(),
'url' => $order->get_edit_order_url(),
'customer_url' => $this->get_customer_url( $order ),
Expand Down

0 comments on commit 8724369

Please sign in to comment.