customerId)->pluck('id'); $transactions = Transaction::whereIn('order_id', $orderIds)->get(); $intents = StripePaymentIntent::whereIn('order_id', $orderIds)->get(); return new ProviderExportResult('payments', [ 'transactions' => $transactions->map(fn (Transaction $transaction) => [ 'id' => $transaction->id, 'order_id' => $transaction->order_id, 'type' => $transaction->type, 'status' => $transaction->status, 'amount' => $transaction->amount, 'card_type' => $transaction->card_type, 'last_four' => $transaction->last_four, 'reference' => $transaction->reference, ])->all(), 'stripe_payment_intents' => $intents->map(fn (StripePaymentIntent $intent) => [ 'id' => $intent->id, 'order_id' => $intent->order_id, 'intent_id' => $intent->intent_id, 'status' => $intent->status, ])->all(), ]); } public function exportForUser(UserSubject $subject): ProviderExportResult { return new ProviderExportResult('payments', []); } public function eraseForCustomer(CustomerSubject $subject): ProviderErasureResult { $orderIds = Order::where('customer_id', $subject->customerId)->pluck('id'); if ($orderIds->isEmpty()) { return new ProviderErasureResult('payments', ErasureOutcome::Skipped, 'No orders, and therefore no payment records, for this customer.'); } Transaction::whereIn('order_id', $orderIds)->update([ 'card_type' => null, 'last_four' => null, ]); // stripe_payment_intents only ever existed to correlate a webhook // callback back to a cart/order (see docs/payments.md "Async // resolution") — that correlation has already served its purpose by // the time an erasure request runs, so these rows are deleted // outright rather than pseudonymized, unlike Transaction, which is // the actual audit-trail record. StripePaymentIntent::whereIn('order_id', $orderIds)->delete(); return new ProviderErasureResult( 'payments', ErasureOutcome::Pseudonymized, 'Card brand/last-four cleared from transaction records; amounts, statuses, and references retained for legal/tax record-keeping. Stripe correlation rows (no longer needed post-settlement) deleted.' ); } public function eraseForUser(UserSubject $subject): ProviderErasureResult { return new ProviderErasureResult('payments', ErasureOutcome::Skipped, 'Payments belong to Customer-owned orders, not individual users.'); } }