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

Change Dispute → Details links to Transaction → Details #7087

Merged
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
194c9c8
Migrate DetailsLink component to TS to improve code quality
Jinksi Aug 29, 2023
869a449
Add changelog entry
Jinksi Aug 29, 2023
06b1983
Add JSDoc annotations for improved devex
Jinksi Aug 29, 2023
ad5194f
Change URL for order notes created on dispute webhook
Jinksi Aug 29, 2023
000ac7e
Update DisputesList rows to link to transaction details
Jinksi Aug 29, 2023
2208df6
Update disputes order notice link to transaction details
Jinksi Aug 29, 2023
37ca6ba
Update the Payments Overview dispute URL to transaction details
Jinksi Aug 29, 2023
d1b54b3
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Sep 15, 2023
a245b13
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Sep 25, 2023
9ae6fe4
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Oct 4, 2023
7a619d1
Update WC home dispute task link to transaction details
Jinksi Oct 4, 2023
011164e
Remove "disputes" from getAdminUrl parentSegment
Jinksi Oct 4, 2023
41439cf
Update PHP tests for marking disputed orders
Jinksi Oct 4, 2023
2dec45c
Fix PHPCS error
Jinksi Oct 4, 2023
c6f10f2
Add changelog entry
Jinksi Oct 4, 2023
266fe7d
Remove transaction dispute details feature flag to enable feature by …
Jinksi Oct 4, 2023
7cc4546
Remove redundant payment details summary test
Jinksi Oct 4, 2023
868ab80
Group dispute-related payment details summary tests
Jinksi Oct 4, 2023
6c40af9
Update snapshot for dispute-reversal test
Jinksi Oct 4, 2023
90834a7
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
Jinksi Oct 4, 2023
c85be9b
Remove unused import
Jinksi Oct 4, 2023
0d37793
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
Jinksi Oct 4, 2023
28e14a5
Fix PHPCS errors
Jinksi Oct 4, 2023
d68f779
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
Jinksi Oct 4, 2023
030262e
Merge branch 'develop' into add/7289-remove-transaction-dispute-detai…
Jinksi Oct 4, 2023
571188f
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
Jinksi Oct 4, 2023
171fe63
Add changelog entry
Jinksi Oct 4, 2023
f5bd338
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
haszari Oct 4, 2023
520a379
Merge branch 'develop' into add/7289-remove-transaction-dispute-detai…
Jinksi Oct 4, 2023
0b3e851
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
haszari Oct 4, 2023
bebbecd
Merge branch 'develop' into add/7289-remove-transaction-dispute-detai…
Jinksi Oct 5, 2023
7efd2ab
Merge branch 'add/7289-remove-transaction-dispute-details-feature-fla…
Jinksi Oct 5, 2023
2e47bb8
Revert changes to DetailsLink component
Jinksi Oct 5, 2023
46c8c74
Revert change of getAdminUrl → getDetailsUrl to simplify PR scope
Jinksi Oct 5, 2023
9d7c3d9
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Oct 5, 2023
ea33d51
Fix PHPCS errors
Jinksi Oct 5, 2023
cab1be8
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
shendy-a8c Oct 5, 2023
27ff3bc
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
shendy-a8c Oct 5, 2023
c73ed05
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
shendy-a8c Oct 5, 2023
8a17ad2
Improve wording of changelog entry
Jinksi Oct 5, 2023
0a958e5
CHange disputed order notice link to transaction details screen
Jinksi Oct 5, 2023
ba300f7
Prefer single quote rather than backtick
Jinksi Oct 5, 2023
ee8df38
Improve `$charge_id` description in docblock
Jinksi Oct 5, 2023
524d291
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Oct 6, 2023
c7aaf93
Merge branch 'develop' into fix/6929-change-dispute-details-links-to-…
Jinksi Oct 6, 2023
dcae68f
Remove unused `$event_type` variables
Jinksi Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Update links that pointed to the dispute details screen to point to the new transaction details screen
Jinksi marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 13 additions & 4 deletions client/disputes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,17 @@ export const DisputesList = (): JSX.Element => {
const rows = disputes.map( ( dispute ) => {
const clickable = ( children: React.ReactNode ): JSX.Element => (
<ClickableCell
href={ getDetailsURL( dispute.dispute_id, 'disputes' ) }
href={ getDetailsURL( dispute.charge_id, 'transactions' ) }
>
{ children }
</ClickableCell>
);

const detailsLink = (
<DetailsLink id={ dispute.dispute_id } parentSegment="disputes" />
<DetailsLink
id={ dispute.charge_id }
parentSegment="transactions"
/>
Jinksi marked this conversation as resolved.
Show resolved Hide resolved
);

const reasonMapping = reasons[ dispute.reason ];
Expand Down Expand Up @@ -303,7 +306,10 @@ export const DisputesList = (): JSX.Element => {
display: (
<Button
variant={ needsResponse ? 'secondary' : 'tertiary' }
href={ getDetailsURL( dispute.dispute_id, 'disputes' ) }
href={ getDetailsURL(
dispute.charge_id,
'transactions'
) }
onClick={ (
e: React.MouseEvent< HTMLAnchorElement >
) => {
Expand All @@ -314,7 +320,10 @@ export const DisputesList = (): JSX.Element => {
);
const history = getHistory();
history.push(
getDetailsURL( dispute.dispute_id, 'disputes' )
getDetailsURL(
dispute.charge_id,
'transactions'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the follow up question is… is it a bad idea to switch all these to getAdminUrl now as part of fixing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I made the choice to change one of these links from getAdminUrlgetDetailsURL since I assumed it was the preferred option for detail screen URLs.

I'm not sure if that's a bad idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all depends on what parentSegment means, and what value it adds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it was the preferred option for detail screen URLs.

What do you prefer and why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To complicate things, getAdminUrl is a wrapper for addQueryArgs – should this be used instead of the wrapper function?

export const getAdminUrl = ( args ) => addQueryArgs( 'admin.php', args );

I think we leave this PR very specific to the scope of the PR and change links only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, probably making extra work to switch over from DetailsLink / getDetailsURL.

To complicate things, getAdminUrl is a wrapper for addQueryArgs – should this be used instead of the wrapper function?

Here's my take…

  • getAdminUrl is a useful, easy to understand API for constructing a url anywhere in Woo admin. We should use it whereever it makes sense.
  • If we have specific boilerplate we end up doing a lot, it might make sense to have our own API, e.g. getWooPaymentsAdminUrl.
    • getDetailsURL is not an improvement over getAdminUrl - makes the code less readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for getAdminUrl – if you understand how it works (what the params mean), that knowledge transfers to addQueryArgs (and vice versa). Not so for DetailsLink and getDetailsURL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you prefer and why?

For this PR, I'd prefer if the changes were specific to the goal. 😆

From a code-quality perspective, I'd like to understand if having the getDetailsUrl with typed parameters helps us in some way before removing it.

Thinking about a developer using getDetailsUrl, it might be a helpful abstraction. They won't have to remember if it is transaction/details, /transactions/details, /payments/transactions/details, %2Ftransactions%2Fdetails etc. The function remembers all of this and TS yells at me if I use the wrong parent (transaction instead of transactions).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point - a typed wrapper of getAdminUrl or getWooPaymentsAdminUrl could add value, though this is orthogonal to my concern that getDetailURL( … parentSegment ) is an unintuitve, weird API.

Copy link
Contributor

@haszari haszari Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find it much easier to read an API like

  • getWooPaymentsUrl( collection: 'transactions' )
  • getWooPaymentsUrl( collection: 'transactions', item: transactionId )

Or more transparently

  • getWooPaymentsUrl( 'transactions' )
  • getWooPaymentsUrl( 'transactions/details/${ transactionId }' )

If you were designing this API, what would it look like?

);
} }
>
Expand Down
46 changes: 23 additions & 23 deletions client/disputes/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
<svg
class="gridicon gridicons-info-outline needs-offset"
Expand All @@ -361,7 +361,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
$10.00
Expand All @@ -373,7 +373,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand All @@ -389,7 +389,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
Transaction unauthorized
Expand All @@ -401,7 +401,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand Down Expand Up @@ -435,7 +435,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand Down Expand Up @@ -463,7 +463,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
class="components-button is-secondary"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_asdfghjkl"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
Respond
</a>
Expand All @@ -476,7 +476,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
<svg
class="gridicon gridicons-info-outline needs-offset"
Expand All @@ -499,7 +499,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
$10.50
Expand All @@ -511,7 +511,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand All @@ -527,7 +527,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
General
Expand All @@ -539,7 +539,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand All @@ -560,7 +560,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
/>
</td>
Expand All @@ -570,7 +570,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
/>
</td>
Expand All @@ -579,7 +579,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
class="components-button is-tertiary"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_zxcvbnm"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
See details
</a>
Expand All @@ -592,7 +592,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
<svg
class="gridicon gridicons-info-outline needs-offset"
Expand All @@ -615,7 +615,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
$20.00
Expand All @@ -627,7 +627,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand All @@ -643,7 +643,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
General
Expand All @@ -655,7 +655,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand All @@ -679,7 +679,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
Mock customer
Expand All @@ -691,7 +691,7 @@ exports[`Disputes list renders correctly 1`] = `
<a
class="woocommerce-table__clickable-cell"
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
tabindex="-1"
>
<span
Expand Down Expand Up @@ -719,7 +719,7 @@ exports[`Disputes list renders correctly 1`] = `
>
<a
class="components-button is-secondary"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdisputes%2Fdetails&id=dp_rstyuoi"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=ch_mock"
>
Respond
</a>
Expand Down
4 changes: 2 additions & 2 deletions client/order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ const DisputeNotice = ( { chargeId } ) => {
}
);
window.location = getDetailsURL(
dispute.id,
'disputes'
chargeId,
'transactions'
);
},
},
Expand Down
8 changes: 4 additions & 4 deletions client/overview/task-list/tasks/dispute-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const getDisputeResolutionTask = (
} );
const history = getHistory();
if ( activeDisputeCount === 1 ) {
// Redirect to the dispute details page if there is only one dispute.
const disputeId = activeDisputes[ 0 ].dispute_id;
// Redirect to the transaction details page if there is only one dispute.
const chargeId = activeDisputes[ 0 ].charge_id;
history.push(
getAdminUrl( {
page: 'wc-admin',
path: '/payments/disputes/details',
id: disputeId,
path: `/payments/transactions/details`,
Jinksi marked this conversation as resolved.
Show resolved Hide resolved
id: chargeId,
} )
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/tasks/class-wc-payments-task-disputes.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public function get_action_url() {
add_query_arg(
[
'page' => 'wc-admin',
'path' => '%2Fpayments%2Fdisputes%2Fdetails',
'id' => $dispute['dispute_id'],
'path' => '%2Fpayments%2Ftransactions%2Fdetails',
'id' => $dispute['charge_id'],
],
'admin.php'
)
Expand Down
36 changes: 18 additions & 18 deletions includes/class-wc-payments-order-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,19 @@ public function mark_order_blocked_for_fraud( $order, $intent_id, $intent_status
* Updates the order to on-hold status and adds a note about the dispute.
*
* @param WC_Order $order Order object.
* @param string $dispute_id The ID of the dispute associated with this order.
* @param string $charge_id The ID of the disputed charge associated with this order.
* @param string $amount The disputed amount – formatted currency value.
* @param string $reason The reason for the dispute – human-readable text.
* @param string $due_by The deadline for responding to the dispute - formatted date string.
*
* @return void
*/
public function mark_payment_dispute_created( $order, $dispute_id, $amount, $reason, $due_by ) {
public function mark_payment_dispute_created( $order, $charge_id, $amount, $reason, $due_by ) {
if ( ! is_a( $order, 'WC_Order' ) ) {
return;
}

$note = $this->generate_dispute_created_note( $dispute_id, $amount, $reason, $due_by );
$note = $this->generate_dispute_created_note( $charge_id, $amount, $reason, $due_by );
if ( $this->order_note_exists( $order, $note ) ) {
return;
}
Expand All @@ -303,17 +303,17 @@ public function mark_payment_dispute_created( $order, $dispute_id, $amount, $rea
* Updates the order status based on dispute status and adds a note about the dispute.
*
* @param WC_Order $order Order object.
* @param string $dispute_id The ID of the dispute associated with this order.
* @param string $charge_id The ID of the disputed charge associated with this order.
* @param string $status The status of the dispute.
*
* @return void
*/
public function mark_payment_dispute_closed( $order, $dispute_id, $status ) {
public function mark_payment_dispute_closed( $order, $charge_id, $status ) {
if ( ! is_a( $order, 'WC_Order' ) ) {
return;
}

$note = $this->generate_dispute_closed_note( $dispute_id, $status );
$note = $this->generate_dispute_closed_note( $charge_id, $status );

if ( $this->order_note_exists( $order, $note ) ) {
return;
Expand Down Expand Up @@ -1218,15 +1218,15 @@ private function generate_fraud_blocked_note( $order ): string {
/**
* Get content for the dispute created order note.
*
* @param string $dispute_id The ID of the dispute associated with this order.
* @param string $charge_id The ID of the disputes charge associated with this order.
* @param string $amount The disputed amount – formatted currency value.
* @param string $reason The reason for the dispute – human-readable text.
* @param string $due_by The deadline for responding to the dispute - formatted date string.
*
* @return string Note content.
*/
private function generate_dispute_created_note( $dispute_id, $amount, $reason, $due_by ) {
$dispute_url = $this->compose_dispute_url( $dispute_id );
private function generate_dispute_created_note( $charge_id, $amount, $reason, $due_by ) {
$dispute_url = $this->compose_dispute_url( $charge_id );

// Get merchant-friendly dispute reason description.
$reason = WC_Payments_Utils::get_dispute_reason_description( $reason );
Expand All @@ -1248,13 +1248,13 @@ private function generate_dispute_created_note( $dispute_id, $amount, $reason, $
/**
* Get content for the dispute closed order note.
*
* @param string $dispute_id The ID of the dispute associated with this order.
* @param string $status The status of the dispute.
* @param string $charge_id The ID of the disputed charge associated with this order.
* @param string $status The status of the dispute.
*
* @return string Note content.
*/
private function generate_dispute_closed_note( $dispute_id, $status ) {
$dispute_url = $this->compose_dispute_url( $dispute_id );
private function generate_dispute_closed_note( $charge_id, $status ) {
$dispute_url = $this->compose_dispute_url( $charge_id );
return sprintf(
WC_Payments_Utils::esc_interpolated_html(
/* translators: %1: the dispute status */
Expand All @@ -1270,16 +1270,16 @@ private function generate_dispute_closed_note( $dispute_id, $status ) {
/**
* Composes url for dispute details page.
*
* @param string $dispute_id Dispute id.
* @param string $charge_id Charge ID.
Jinksi marked this conversation as resolved.
Show resolved Hide resolved
*
* @return string Dispute details page url.
* @return string Transaction details page url.
*/
private function compose_dispute_url( $dispute_id ) {
private function compose_dispute_url( $charge_id ) {
return add_query_arg(
[
'page' => 'wc-admin',
'path' => '/payments/disputes/details',
'id' => $dispute_id,
'path' => '/payments/transactions/details',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice one of the URL from the dispute order note has / in the query string parameter value. Forward slash should be encoded to %2F.

Screen.Recording.2023-10-06.at.01.48.22.mov

To confirm encodeURIComponent('/') in Javascript would return %2F.

I was surprised add_query_arg() does not encode the parameter value but then I read that it expects the parameter value is already encoded.

Suggested change
'path' => '/payments/transactions/details',
'path' => '%2Fpayments%2Ftransactions%2Fdetails',

or

Suggested change
'path' => '/payments/transactions/details',
'path' => urlencode( '/payments/transactions/details' ),

Copy link
Member Author

@Jinksi Jinksi Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this and it ends up with a malformed URL with 0.00000 inserted in place of //%2F.

/wp-admin/admin.php?page=wc-admin&path=0.000000payments0.000000transactions0.000000details&id=ch_3Ny06gC15a3WbJ1t14zIF3QB

This URL is being processed by through WC_Payments_Utils::esc_interpolated_html(), so I'll see if there's another way to urlencode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow wow. Not sure what's going on there. I only tried it on WP Console.

Screenshot 2023-10-06 at 08 50 23

Let's do it in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened an issue for this: #7399.

'id' => $charge_id,
],
admin_url( 'admin.php' )
);
Expand Down
Loading
Loading