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

Improve the dispute created message #3671

Merged
merged 12 commits into from
Dec 20, 2024
Merged

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Dec 18, 2024

Fixes #1233

Changes proposed in this Pull Request:

Most times, when a dispute is open, no actions are needed. It is either already lost or won. The current note we add to the order implies that an action is always required. This PR fixes that by checking the dispute status and setting the note accordingly.

Testing instructions

Since this is a bit hard to test, code review should be enough. But if you want to try testing the flow:

  • Checkout and build this branch on your test environment (fix/improve-dispute-created-message)
  • Connect your Stripe account
  • Configure webhooks
  • As a shopper, add a product to your cart
  • Go to the checkout page
  • Use any regular card to complete the purchase
  • Copy the sample dispute opened event body below
Sample event
{
  "object": {
    "id": "dp_1QXkGcGwEEw4tjx0ElVhWtCa",
    "object": "dispute",
    "amount": 1100,
    "balance_transaction": "txn_1QXkGdGwEEw4tjx0E923VfyN",
    "balance_transactions": [
      {
        "id": "txn_1QXkGdGwEEw4tjx0E923VfyN",
        "object": "balance_transaction",
        "amount": -1100,
        "available_on": 1735171200,
        "created": 1734616794,
        "currency": "usd",
        "description": "Chargeback withdrawal for ch_3QXkGbGwEEw4tjx01pt9gIJe",
        "exchange_rate": null,
        "fee": 1500,
        "fee_details": [
          {
            "amount": 1500,
            "application": null,
            "currency": "usd",
            "description": "Dispute fee",
            "type": "stripe_fee"
          }
        ],
        "net": -2600,
        "reporting_category": "dispute",
        "source": "dp_1QXkGcGwEEw4tjx0ElVhWtCa",
        "status": "pending",
        "type": "adjustment"
      }
    ],
    "charge": "ch_3QXkGbGwEEw4tjx01pt9gIJe",
    "created": 1734616794,
    "currency": "usd",
    "enhanced_eligibility_types": [
    ],
    "evidence": {
      "access_activity_log": null,
      "billing_address": "1600 Amphitheatre Parkway\n\nMountain View, CA, 94043, US",
      "cancellation_policy": null,
      "cancellation_policy_disclosure": null,
      "cancellation_rebuttal": null,
      "customer_communication": null,
      "customer_email_address": "[email protected]",
      "customer_name": "Card Holder Name",
      "customer_purchase_ip": null,
      "customer_signature": null,
      "duplicate_charge_documentation": null,
      "duplicate_charge_explanation": null,
      "duplicate_charge_id": null,
      "enhanced_evidence": {
      },
      "product_description": null,
      "receipt": null,
      "refund_policy": null,
      "refund_policy_disclosure": null,
      "refund_refusal_explanation": null,
      "service_date": null,
      "service_documentation": null,
      "shipping_address": "1600 Amphitheatre Parkway\n\nMountain View, CA, 94043, US",
      "shipping_carrier": null,
      "shipping_date": null,
      "shipping_documentation": null,
      "shipping_tracking_number": null,
      "uncategorized_file": null,
      "uncategorized_text": null
    },
    "evidence_details": {
      "due_by": 1735430399,
      "enhanced_eligibility": {
      },
      "has_evidence": false,
      "past_due": false,
      "submission_count": 0
    },
    "is_charge_refundable": false,
    "livemode": false,
    "metadata": {
    },
    "payment_intent": "pi_3QXkGbGwEEw4tjx01PkubTsY",
    "payment_method_details": {
      "card": {
        "brand": "visa",
        "case_type": "chargeback",
        "network_reason_code": "83"
      },
      "type": "card"
    },
    "reason": "fraudulent",
    "status": "lost"
  }
}
(change `object.charge` property to match your charge ID. You can grab it on your Stripe dashboard or the order edit page) - Request the webhook endpoint on your store using the event body (`/?wc-api=wc_stripe`) using Postman or something similar
  • Confirm the order gets updated with the correct note:
    "A dispute was created for this order. It was closed as lost or accepted."

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

@wjrosa wjrosa self-assigned this Dec 18, 2024
@wjrosa wjrosa marked this pull request as ready for review December 19, 2024 14:12
@wjrosa wjrosa requested review from a team and Mayisha and removed request for a team December 19, 2024 14:12
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

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

Thanks @wjrosa. I have added a little suggestion. Otherwise looks good to me 👍

includes/class-wc-stripe-webhook-handler.php Outdated Show resolved Hide resolved
@wjrosa wjrosa merged commit 9691ad8 into develop Dec 20, 2024
33 of 35 checks passed
@wjrosa wjrosa deleted the fix/improve-dispute-created-message branch December 20, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify that dispute needs response before saying so?
2 participants