Bc payments cancel subscription and refund

From breatheco-de/apiv2 · View interactive version

Bc payments cancel subscription and refund is an AI agent skill from the GitHub repository breatheco-de/apiv2. Use when implementing self-serve cancellation or staff-driven cancellation with optional invoice refunds; do NOT use for consumption-session reversals, mentorship refund tasks, or payment-method setup.

How to use this skill

Skill file

Skill: Cancel Subscription and Optionally Refund

When to Use

Use this skill when a product flow needs to cancel a subscription for a standard user or for staff and optionally refund a paid invoice.

Use it when the UI must decide between cancel-only vs cancel-plus-refund behavior.

Do NOT use this skill for void consumption reversals, mentorship session reimbursement, or payment method onboarding.

Concepts

Workflow

  1. Identify actor and intent.
  1. For standard users, fetch current subscriptions and show cancelable items.
  1. For standard users, cancel subscription.
  1. For staff, resolve target user and active payment objects.
  1. If staff chooses cancel-only, update subscription status.
  1. If staff chooses refund, validate refundability in the UI before submit.
  1. Submit refund request.
  1. Sync post-action state.
flowchart TD
  startFlow[Start]
  actorDecision{ActorType}
  userList[GetMeSubscriptions]
  userCancel[CancelMeSubscription]
  staffList[GetAcademySubscriptionsAndInvoices]
  refundDecision{RefundNeeded}
  staffCancelOnly[PutAcademySubscriptionCancelled]
  prepareRefund[BuildRefundPayload]
  submitRefund[PostInvoiceRefund]
  refreshState[RefreshSubscriptionAndInvoice]
  endFlow[End]
  startFlow --> actorDecision
  actorDecision -->|user| userList
  userList --> userCancel
  userCancel --> refreshState
  actorDecision -->|staff| staffList
  staffList --> refundDecision
  refundDecision -->|no| staffCancelOnly
  staffCancelOnly --> refreshState
  refundDecision -->|yes| prepareRefund
  prepareRefund --> submitRefund
  submitRefund --> refreshState
  refreshState --> endFlow

Endpoints

1) Get current user subscriptions

Sample response (subset):

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 321,
      "status": "ACTIVE",
      "invoices": [
        {
          "id": 9876,
          "amount": 120.0,
          "amount_refunded": 0.0,
          "currency": {
            "code": "USD"
          }
        }
      ]
    }
  ]
}

2) Cancel current user subscription

Sample request body:

{}

Sample response (subset):

{
  "id": 321,
  "status": "CANCELLED",
  "next_payment_at": "2026-05-01T00:00:00Z"
}

3) Staff list subscriptions

Sample response (subset):

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 321,
      "status": "ACTIVE",
      "user": 445,
      "invoices": [
        {
          "id": 9876,
          "amount": 120.0,
          "amount_refunded": 0.0
        }
      ]
    }
  ]
}

4) Staff update subscription status

Sample request body:

{
  "status": "CANCELLED"
}

Sample response:

{
  "detail": "Subscription updated successfully"
}

5) Staff list invoices

Sample response (subset):

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 9876,
      "status": "FULFILLED",
      "amount": 120.0,
      "amount_refunded": 0.0,
      "stripe_id": "ch_3QX123abc456",
      "amount_breakdown": {
        "plans": {
          "full-stack-plan": {
            "amount": 120.0
          }
        },
        "service-items": {}
      }
    }
  ]
}

6) Staff refund invoice

Sample request body:

{
  "refund_amount": 120.0,
  "items_to_refund": {
    "full-stack-plan": 120.0
  },
  "plan_entitlement_action": "cancel_at_period_end",
  "reason": "Customer requested cancellation during trial period."
}

Sample response (subset):

{
  "id": 501,
  "invoice": 9876,
  "amount": 120.0,
  "currency": "USD",
  "status": "ISSUED",
  "refund_stripe_id": "re_3QX999abc111"
}

7) Staff record external refund (no Stripe call)

Sample request body:

{
  "refund_amount": 120.0,
  "items_to_refund": {
    "full-stack-plan": 120.0
  },
  "reason": "Refund was issued manually in finance operations.",
  "external_reference": "ticket-88421",
  "stripe_refund_id": "re_3QX999abc111"
}

Sample response (subset):

{
  "id": 502,
  "invoice": 9876,
  "amount": 120.0,
  "currency": "USD",
  "status": "ISSUED",
  "refund_stripe_id": "re_3QX999abc111"
}

Edge Cases

  1. Subscription already cancelled or deprecated.
  1. Subscription not found.
  1. Subscription missing from default list.
  1. Invoice already fully refunded.
  1. Refund amount mismatch.
  1. Invalid slugs in items_to_refund.
  1. Missing invoice breakdown.
  1. Non-refundable invoice state.
  1. Partial refund follow-up.
  1. Multi-invoice subscriptions (renewals).
  1. Stripe vs non-Stripe charge (stripe_id).
  1. Language and message handling.
  1. External refund already issued outside the API.

Checklist

  1. Determine whether the actor is standard user or staff before selecting endpoint path.
  2. For cancel-only flows, submit cancellation and refresh the latest subscription state.
  3. For refund flows, select the correct invoice and validate refundable balance before submit.
  4. Build items_to_refund from invoice breakdown slugs and keep totals equal to refund_amount.
  5. Handle translated error slugs for idempotency, invalid payloads, and non-refundable states.
  6. Record and display returned credit note details after successful refund.
  7. Use /record-refund (not /refund) when money was already refunded outside this API.
  8. Align success messaging with stripe_id and endpoint path: Stripe payout initiated vs reconciliation-only update.
  9. Use this detail reference for refund behavior and side effects: CODE0.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.