Payment Refund Implementation

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    848
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementation of Payment Refund on Website

Payment refund is not just calling one API method. Correct implementation includes order status verification, balance updates, notifications, fiscal receipts and edge case handling. Without this get appearance of refund, but money either doesn't return or returns twice.

Development takes 2–4 business days depending on payment methods count and fiscalization requirements.

Refund Lifecycle

Refund goes through states: pending → processing → succeeded or failed. User initiates request, manager (or automation) confirms, system sends request to gateway, gateway processes and returns result via webhook.

Never show customer "refund completed" before receiving payment gateway confirmation.

Stripe Refund API

Basic refund via Stripe:

$refund = \Stripe\Refund::create([
    'payment_intent' => $order->stripe_payment_intent_id,
    'amount'         => $refundAmountCents, // omit for full refund
    'reason'         => 'requested_by_customer', // duplicate, fraudulent
    'metadata'       => ['order_id' => $order->id, 'reason_text' => $reason],
]);

Stripe processes refunds asynchronously. Final status comes in webhook charge.refund.updated. Must handle this, not rely on sync response:

public function handleRefundUpdated(array $payload): void
{
    $refund = $payload['data']['object'];

    $localRefund = Refund::where('stripe_refund_id', $refund['id'])->firstOrFail();
    $localRefund->update(['status' => $refund['status']]);

    if ($refund['status'] === 'succeeded') {
        $localRefund->order->update(['refund_status' => 'refunded']);
        $this->restoreStock($localRefund->order);
        $this->sendRefundConfirmation($localRefund->order);
        $this->issueFiscalRefundReceipt($localRefund);
    }

    if ($refund['status'] === 'failed') {
        Log::error('Refund failed', ['stripe_refund_id' => $refund['id'], 'failure_reason' => $refund['failure_reason']]);
        $this->notifySupport($localRefund);
    }
}

Refund DB Model

CREATE TABLE refunds (
    id                 bigserial PRIMARY KEY,
    order_id           bigint         NOT NULL REFERENCES orders(id),
    stripe_refund_id   varchar(100)   UNIQUE,
    amount_cents       int            NOT NULL,
    currency           char(3)        NOT NULL DEFAULT 'rub',
    status             varchar(20)    NOT NULL DEFAULT 'pending',
    reason             text,
    initiated_by       bigint         REFERENCES users(id), -- null = automatic
    fiscal_receipt_id  varchar(100),
    created_at         timestamptz    NOT NULL DEFAULT now(),
    updated_at         timestamptz    NOT NULL DEFAULT now()
);

Separate refunds table, not flag in orders — allows multiple partial refunds and history.

Validation and Checks Before Refund

public function validateRefundRequest(Order $order, int $amountCents): void
{
    if (!in_array($order->payment_status, ['paid', 'partially_refunded'])) {
        throw new RefundException('Order not paid or fully refunded');
    }

    $alreadyRefunded = $order->refunds()->where('status', 'succeeded')->sum('amount_cents');
    $available = $order->total_cents - $alreadyRefunded;

    if ($amountCents > $available) {
        throw new RefundException("Maximum refund amount: {$available} kopeks");
    }

    $daysSincePurchase = now()->diffInDays($order->paid_at);
    if ($daysSincePurchase > 365) {
        throw new RefundException('Refunds only possible within 365 days of payment');
    }
}

Stripe limits refunds to 1 year. CloudPayments 13 months. YooKassa 3 years. Each provider has limits, check docs.

Fiscal Receipt on Refund

In Russia when returning money, cash register must print receipt with "return of receipt" indicator. For Atol Online / OFD integrations:

$receipt = [
    'type'    => 'refund',
    'items'   => array_map(fn($item) => [
        'name'     => $item->product_name,
        'price'    => $item->unit_price / 100,
        'quantity' => $item->quantity,
        'sum'      => $item->total_price / 100,
        'tax'      => 'vat20',
        'payment_method' => 'full_payment',
        'payment_object' => 'commodity',
    ], $order->refundItems),
    'payments' => [['type' => 1, 'sum' => $refundAmount / 100]],
    'total'   => $refundAmount / 100,
    'email'   => $order->customer_email,
];

Refund receipt must be issued regardless of whether refund initiated by customer or store.

Refund for Non-Card Methods

For cash, bank transfer, SBP — automatic API refund impossible. Implement scenario with manual processing: manager confirms return fact, system updates status. For COD — often means sending cash by courier or bank transfer — must be documented in interface.