Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added payment details with card checks and captures to order payments (#14916)

Damian Legawieca7aa0e51f1e7
diff --git a/.changeset/payment-details-dialog.md b/.changeset/payment-details-dialog.md
new file mode 100644
index 0000000000..b5e720535f
--- /dev/null
+++ b/.changeset/payment-details-dialog.md
@@ -0,0 +1,6 @@
+---
+"@spree/admin-sdk": minor
+"@spree/dashboard": minor
+---
+
+Admin API payments now include `avs_risky` and `cvv_risky`, and can expand `capture_events`, each capture of the money the payment authorized. On the order page, a payment whose card failed the issuer's checks is flagged, and each payment's menu opens a details dialog with the address and security code check results and the list of captures.
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index 4108ee4b2a..be791885d0 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -21615,6 +21615,8 @@ paths:
gateway_dashboard_payment_url: https://dashboard.bogus.example/payments/BGS-343039b69b86
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
+ avs_risky: false
+ cvv_risky: false
captured_amount: '0.00'
order_id: or_UkLWZg9DAJ
meta:
@@ -21697,6 +21699,8 @@ paths:
gateway_dashboard_payment_url:
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
+ avs_risky: false
+ cvv_risky: false
captured_amount: '0.00'
order_id: or_gbHJdmfrXB
requestBody:
@@ -21805,6 +21809,8 @@ paths:
gateway_dashboard_payment_url: https://dashboard.bogus.example/payments/BGS-4a236d40ef07
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
+ avs_risky: false
+ cvv_risky: false
captured_amount: '0.00'
order_id: or_UkLWZg9DAJ
"/api/v3/admin/orders/{order_id}/payments/{id}/capture":
@@ -21894,6 +21900,8 @@ paths:
gateway_dashboard_payment_url: https://dashboard.bogus.example/payments/BGS-ccc19f06b194
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
+ avs_risky: false
+ cvv_risky: false
captured_amount: '110.00'
order_id: or_UkLWZg9DAJ
'422':
@@ -21997,6 +22005,8 @@ paths:
gateway_dashboard_payment_url: https://dashboard.bogus.example/payments/void-BGS-11f2e975ba0c
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
+ avs_risky: false
+ cvv_risky: false
captured_amount: '0.00'
order_id: or_UkLWZg9DAJ
"/api/v3/admin/price_lists":
@@ -63790,6 +63800,23 @@ components:
- seller_id
- seller_name
x-typelizer: true
+ PaymentCaptureEvent:
+ type: object
+ properties:
+ id:
+ type: string
+ created_at:
+ type: string
+ updated_at:
+ type: string
+ amount:
+ type: string
+ required:
+ - id
+ - created_at
+ - updated_at
+ - amount
+ x-typelizer: true
PaymentMethod:
type: object
properties:
@@ -63928,11 +63955,23 @@ components:
type: string
updated_at:
type: string
+ avs_risky:
+ type: boolean
+ description: Whether the card issuer reported that the billing address did
+ not match.
+ cvv_risky:
+ type: boolean
+ description: Whether the card issuer reported that the security code did
+ not match.
captured_amount:
type: string
order_id:
type: string
nullable: true
+ capture_events:
+ type: array
+ items:
+ "$ref": "#/components/schemas/PaymentCaptureEvent"
order:
"$ref": "#/components/schemas/Order"
refunds:
@@ -63960,6 +63999,8 @@ components:
- gateway_dashboard_payment_url
- created_at
- updated_at
+ - avs_risky
+ - cvv_risky
- captured_amount
- order_id
x-typelizer: true
diff --git a/packages/admin-sdk/src/types/generated/Payment.ts b/packages/admin-sdk/src/types/generated/Payment.ts
index d51d615af1..32b69753ad 100644
--- a/packages/admin-sdk/src/types/generated/Payment.ts
+++ b/packages/admin-sdk/src/types/generated/Payment.ts
@@ -1,7 +1,7 @@
-// Typelizer digest 0df274b81a7420628c2f56d2966eb4fc
+// Typelizer digest 4c466bf3ac1117acca6f28a528dd8f2e
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {CreditCard, StoreCredit, PaymentSource, PaymentMethod, Order, Refund, PaymentSplit, PaymentStatus} from '@/types'
+import type {CreditCard, StoreCredit, PaymentSource, PaymentMethod, PaymentCaptureEvent, Order, Refund, PaymentSplit, PaymentStatus} from '@/types'
interface Payment {
id: string;
@@ -21,8 +21,13 @@ interface Payment {
gateway_dashboard_payment_url: string | null;
created_at: string;
updated_at: string;
+ /** Whether the card issuer reported that the billing address did not match. */
+ avs_risky: boolean;
+ /** Whether the card issuer reported that the security code did not match. */
+ cvv_risky: boolean;
captured_amount: string;
order_id: string | null;
+ capture_events?: Array<PaymentCaptureEvent>;
order?: Order;
refunds?: Array<Refund>;
payment_splits?: Array<PaymentSplit>;
diff --git a/packages/admin-sdk/src/types/generated/PaymentCaptureEvent.ts b/packages/admin-sdk/src/types/generated/PaymentCaptureEvent.ts
new file mode 100644
index 0000000000..5c706c3883
--- /dev/null
+++ b/packages/admin-sdk/src/types/generated/PaymentCaptureEvent.ts
@@ -0,0 +1,12 @@
+// Typelizer digest 1170f380d49d13519f55b27036e0a080
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+interface PaymentCaptureEvent {
+ id: string;
+ created_at: string;
+ updated_at: string;
+ amount: string;
+}
+
+export default PaymentCaptureEvent;
diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.ts
index d34d3900c4..ee86354099 100644
--- a/packages/admin-sdk/src/types/generated/index.ts
+++ b/packages/admin-sdk/src/types/generated/index.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 68c268fa4531bf238b43969cb511355a
+// Typelizer digest bdb7ea3ea25ffd19b87cc9b216fa3f49
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { ActorKind, ClaimStatus, CountryCode, CurrencyCode, DataRequestStatus, ExchangeStatus, FeeKind, FulfillmentItemStatus, FulfillmentStatus, GiftCardStatus, ImportRowStatus, ImportStatus, InvitationStatus, LocaleCode, PaymentStatus, PriceListStatus, ProductStatus, ProductSubmissionStatus, ReturnStatus, SellerPayoutStatus, SellerRequirementSubmissionStatus, SellerStatus, SellerTransferStatus, ShippingLabelStatus, StockLocationKind, TaxExemptionCertificateStatus } from './Enums'
@@ -88,6 +88,7 @@ export type { default as OrderGroup } from './OrderGroup'
export type { default as OrderRoutingRule } from './OrderRoutingRule'
export type { default as Order } from './Order'
export type { default as PackageType } from './PackageType'
+export type { default as PaymentCaptureEvent } from './PaymentCaptureEvent'
export type { default as PaymentMethod } from './PaymentMethod'
export type { default as Payment } from './Payment'
export type { default as PaymentSource } from './PaymentSource'
diff --git a/packages/admin-sdk/src/zod/generated/Payment.ts b/packages/admin-sdk/src/zod/generated/Payment.ts
index 61a4cd8b53..5b145dff02 100644
--- a/packages/admin-sdk/src/zod/generated/Payment.ts
+++ b/packages/admin-sdk/src/zod/generated/Payment.ts
@@ -2,6 +2,7 @@
import { z } from 'zod';
import { CreditCardSchema } from './CreditCard';
import { OrderSchema } from './Order';
+import { PaymentCaptureEventSchema } from './PaymentCaptureEvent';
import { PaymentMethodSchema } from './PaymentMethod';
import { PaymentSourceSchema } from './PaymentSource';
import { PaymentSplitSchema } from './PaymentSplit';
@@ -26,8 +27,11 @@ export const PaymentSchema = z.object({
gateway_dashboard_payment_url: z.string().nullable(),
created_at: z.string(),
updated_at: z.string(),
+ avs_risky: z.boolean(),
+ cvv_risky: z.boolean(),
captured_amount: z.string(),
order_id: z.string().nullable(),
+ capture_events: z.array(PaymentCaptureEventSchema).optional(),
get order() { return OrderSchema.optional(); },
get refunds() { return z.array(RefundSchema).optional(); },
payment_splits: z.array(PaymentSplitSchema).optional(),
diff --git a/packages/admin-sdk/src/zod/generated/PaymentCaptureEvent.ts b/packages/admin-sdk/src/zod/generated/PaymentCaptureEvent.ts
new file mode 100644
index 0000000000..8d294aad34
--- /dev/null
+++ b/packages/admin-sdk/src/zod/generated/PaymentCaptureEvent.ts
@@ -0,0 +1,11 @@
+// This file is auto-generated. Do not edit directly.
+import { z } from 'zod';
+
+export const PaymentCaptureEventSchema = z.object({
+ id: z.string(),
+ created_at: z.string(),
+ updated_at: z.string(),
+ amount: z.string(),
+});
+
+export type PaymentCaptureEvent = z.infer<typeof PaymentCaptureEventSchema>;
diff --git a/packages/admin-sdk/src/zod/generated/index.ts b/packages/admin-sdk/src/zod/generated/index.ts
index 993017e69e..9d88c5ef3b 100644
--- a/packages/admin-sdk/src/zod/generated/index.ts
+++ b/packages/admin-sdk/src/zod/generated/index.ts
@@ -86,6 +86,7 @@ export { OrderGroupSchema, type OrderGroup } from './OrderGroup';
export { OrderRoutingRuleSchema, type OrderRoutingRule } from './OrderRoutingRule';
export { PackageTypeSchema, type PackageType } from './PackageType';
export { PaymentSchema, type Payment } from './Payment';
+export { PaymentCaptureEventSchema, type PaymentCaptureEvent } from './PaymentCaptureEvent';
export { PaymentMethodSchema, type PaymentMethod } from './PaymentMethod';
export { PaymentSourceSchema, type PaymentSource } from './PaymentSource';
export { PaymentSplitSchema, type PaymentSplit } from './PaymentSplit';
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 9aaaed3341..5ff9a57b88 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -184,13 +184,14 @@ const BOOTSTRAP_RUBY = [
`comma_store.markets.find_or_create_by!(name: 'United States') { |m| m.currency = 'USD'; m.default_locale = 'en'; m.countries = [Spree::Country.find_by_iso!('US')] } unless comma_store.markets.exists?(currency: 'USD')`,
'comma_store.add_user(admin, Spree::Role.default_admin_role(comma_store)) unless comma_store.role_users.exists?(user: admin)',
// A card payment the Bogus gateway has charged, so its page at the gateway's
- // dashboard has an address. On this store because the payment method specs
- // install Bogus on the default one, and a store holds each provider once.
- // Written directly: charging a card needs a full checkout.
+ // dashboard has an address, and whose card failed both of the issuer's
+ // checks. On this store because the payment method specs install Bogus on the
+ // default one, and a store holds each provider once. Written directly:
+ // charging a card needs a full checkout.
`comma_bogus = comma_store.payment_methods.where(type: 'Spree::Gateway::Bogus').first_or_create!(name: '${FIXTURE_BOGUS_GATEWAY}', active: true, storefront_visible: false)`,
`gateway_order = comma_store.orders.find_by(email: '${FIXTURE_BOGUS_ORDER_EMAIL}') || Spree::Order.create!(store: comma_store, currency: 'EUR', email: '${FIXTURE_BOGUS_ORDER_EMAIL}', status: 'placed', completed_at: Time.current, total: 10)`,
"gateway_card = Spree::CreditCard.where(payment_method: comma_bogus, gateway_customer_profile_id: 'BGS-E2E').first_or_create!(number: '4111111111111111', verification_value: '123', month: 12, year: 1.year.from_now.year, name: 'E2E Customer', cc_type: 'visa')",
- `gateway_order.payments.create!(payment_method: comma_bogus, source: gateway_card, amount: 10, status: 'completed', response_code: '${FIXTURE_BOGUS_TRANSACTION_ID}') unless gateway_order.payments.exists?`,
+ `gateway_order.payments.create!(payment_method: comma_bogus, source: gateway_card, amount: 10, status: 'completed', response_code: '${FIXTURE_BOGUS_TRANSACTION_ID}', avs_response: 'N', cvv_response_code: 'N', cvv_response_message: 'CVV does not match').capture_events.create!(amount: 10) unless gateway_order.payments.exists?`,
'port = ENV.fetch("PORT", 3010)',
'puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name, comma_store_id: comma_store.prefixed_id)',
].join('; ')
diff --git a/packages/dashboard/e2e/orders.spec.ts b/packages/dashboard/e2e/orders.spec.ts
index 38c8b2f874..d62912251f 100644
--- a/packages/dashboard/e2e/orders.spec.ts
+++ b/packages/dashboard/e2e/orders.spec.ts
@@ -380,4 +380,27 @@ test.describe('order payments', () => {
)
await expect(link).toHaveAttribute('target', '_blank')
})
+
+ test("shows a card payment's checks and captures", async ({ page }) => {
+ const creds = await login(page)
+ const orders = await adminRequest<{ data: { id: string }[] }>(
+ page,
+ { ...creds, store_id: creds.comma_store_id },
+ 'get',
+ `/orders?q[email_eq]=${encodeURIComponent(FIXTURE_BOGUS_ORDER_EMAIL)}`,
+ )
+ await page.goto(`/${creds.comma_store_id}/orders/${orders.data[0].id}`)
+
+ const row = page.locator('tr').filter({ hasText: FIXTURE_BOGUS_GATEWAY })
+ await expect(row.getByText('Failed card checks')).toBeVisible({ timeout: 15_000 })
+
+ await row.getByRole('button', { name: /^actions$/i }).click()
+ await page.getByRole('menuitem', { name: 'View details' }).click()
+
+ const dialog = page.getByRole('dialog')
+ await expect(dialog.getByText(FIXTURE_BOGUS_TRANSACTION_ID)).toBeVisible()
+ await expect(dialog.getByText('Did not pass')).toHaveCount(2)
+ await expect(dialog.getByText('CVV does not match')).toBeVisible()
+ await expect(dialog.getByRole('row').filter({ hasText: '€10.00' })).toBeVisible()
+ })
})
diff --git a/packages/dashboard/src/components/spree/orders/order-payments-card.tsx b/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
index 5a2f5409fa..de92afb85f 100644
--- a/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
@@ -46,7 +46,9 @@ import {
CreditCardIcon,
EllipsisVerticalIcon,
ExternalLinkIcon,
+ InfoIcon,
PlusIcon,
+ ShieldAlertIcon,
XCircleIcon,
} from '@spree/dashboard-ui/icons'
import { useQuery } from '@tanstack/react-query'
@@ -55,6 +57,7 @@ import { type FormEvent, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useOrderMutation } from '../../../hooks/use-order'
import { useOrderGroup } from '../../../hooks/use-seller-ledger'
+import { PaymentDetailsDialog } from './payment-details-dialog'
export function PaymentsCard({ order }: { order: Order }) {
const { t } = useTranslation()
@@ -156,7 +159,15 @@ export function PaymentsCard({ order }: { order: Order }) {
{payment.payment_method?.name ?? '—'}
</TableCell>
<TableCell>
- <StatusBadge status={payment.status} />
+ <div className="flex flex-wrap items-center gap-1.5">
+ <StatusBadge status={payment.status} />
+ {(payment.avs_risky || payment.cvv_risky) && (
+ <Badge variant="warning">
+ <ShieldAlertIcon />
+ {t('admin.orders.detail.payments_table.failed_card_checks')}
+ </Badge>
+ )}
+ </div>
</TableCell>
<TableCell className="text-right font-medium whitespace-nowrap tabular-nums">
<Money amount={payment.amount} currency={order.currency} />
@@ -174,6 +185,7 @@ export function PaymentsCard({ order }: { order: Order }) {
<TableCell>
<PaymentActionsMenu
payment={payment}
+ currency={order.currency}
// Capturing or voiding a grouped payment acts on every
// order in the checkout, so this page only links out.
canCapture={
@@ -222,54 +234,68 @@ export function PaymentsCard({ order }: { order: Order }) {
function PaymentActionsMenu({
payment,
+ currency,
canCapture,
canVoid,
onCapture,
onVoid,
}: {
payment: Payment
+ currency: string
canCapture: boolean
canVoid: boolean
onCapture: () => void
onVoid: () => void
}) {
const { t } = useTranslation()
+ const [detailsOpen, setDetailsOpen] = useState(false)
const dashboardUrl = payment.gateway_dashboard_payment_url
- if (!canCapture && !canVoid && !dashboardUrl) return null
return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="icon-xs">
- <EllipsisVerticalIcon className="size-4" />
- <span className="sr-only">{t('admin.actions.actions_menu')}</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {dashboardUrl && (
- <DropdownMenuItem asChild>
- <a href={dashboardUrl} target="_blank" rel="noopener noreferrer">
- <ExternalLinkIcon className="size-4" />
- {t('admin.orders.detail.payments_table.view_at_gateway', {
- gateway: payment.payment_method?.name,
- })}
- </a>
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs">
+ <EllipsisVerticalIcon className="size-4" />
+ <span className="sr-only">{t('admin.actions.actions_menu')}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={() => setDetailsOpen(true)}>
+ <InfoIcon className="size-4" />
+ {t('admin.orders.detail.payments_table.view_details')}
</DropdownMenuItem>
- )}
- {canCapture && (
- <DropdownMenuItem onClick={onCapture}>
- <CreditCardIcon className="size-4" />
- {t('admin.pages.orders.detail.actions.capture')}
- </DropdownMenuItem>
- )}
- {canVoid && (
- <DropdownMenuItem variant="destructive" onClick={onVoid}>
- <XCircleIcon className="size-4" />
- {t('admin.pages.orders.detail.actions.void')}
- </DropdownMenuItem>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
+ {dashboardUrl && (
+ <DropdownMenuItem asChild>
+ <a href={dashboardUrl} target="_blank" rel="noopener noreferrer">
+ <ExternalLinkIcon className="size-4" />
+ {t('admin.orders.detail.payments_table.view_at_gateway', {
+ gateway: payment.payment_method?.name,
+ })}
+ </a>
+ </DropdownMenuItem>
+ )}
+ {canCapture && (
+ <DropdownMenuItem onClick={onCapture}>
+ <CreditCardIcon className="size-4" />
+ {t('admin.pages.orders.detail.actions.capture')}
+ </DropdownMenuItem>
+ )}
+ {canVoid && (
+ <DropdownMenuItem variant="destructive" onClick={onVoid}>
+ <XCircleIcon className="size-4" />
+ {t('admin.pages.orders.detail.actions.void')}
+ </DropdownMenuItem>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <PaymentDetailsDialog
+ payment={payment}
+ currency={currency}
+ open={detailsOpen}
+ onOpenChange={setDetailsOpen}
+ />
+ </>
)
}
diff --git a/packages/dashboard/src/components/spree/orders/payment-details-dialog.tsx b/packages/dashboard/src/components/spree/orders/payment-details-dialog.tsx
new file mode 100644
index 0000000000..8344fd1709
--- /dev/null
+++ b/packages/dashboard/src/components/spree/orders/payment-details-dialog.tsx
@@ -0,0 +1,187 @@
+import type { Payment } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
+import {
+ Badge,
+ Button,
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ RelativeTime,
+ StatusBadge,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '@spree/dashboard-ui'
+import { ExternalLinkIcon } from '@spree/dashboard-ui/icons'
+import { useTranslation } from 'react-i18next'
+
+type CheckOutcome = 'passed' | 'failed' | 'not_checked'
+
+const OUTCOME_VARIANTS = {
+ passed: 'success',
+ failed: 'destructive',
+ not_checked: 'outline',
+} as const
+
+function addressCheck(payment: Payment): CheckOutcome {
+ if (!payment.avs_response) return 'not_checked'
+ return payment.avs_risky ? 'failed' : 'passed'
+}
+
+function securityCodeCheck(payment: Payment): CheckOutcome {
+ if (!payment.cvv_response_code) return 'not_checked'
+ return payment.cvv_risky ? 'failed' : 'passed'
+}
+
+/** What the card issuer reported about a payment, and each capture of its money. */
+export function PaymentDetailsDialog({
+ payment,
+ currency,
+ open,
+ onOpenChange,
+}: {
+ payment: Payment
+ currency: string
+ open: boolean
+ onOpenChange: (open: boolean) => void
+}) {
+ const { t } = useTranslation()
+ const captures = payment.capture_events ?? []
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent className="sm:max-w-lg">
+ <DialogHeader>
+ <DialogTitle>
+ {t('admin.orders.detail.payment_details.title', { number: payment.number })}
+ </DialogTitle>
+ <DialogDescription>
+ {t('admin.orders.detail.payment_details.description')}
+ </DialogDescription>
+ </DialogHeader>
+ <DialogBody className="flex flex-col gap-6">
+ <dl className="grid grid-cols-[auto_1fr] gap-x-6 gap-y-2 text-sm">
+ <dt className="text-muted-foreground">
+ {t('admin.orders.detail.payments_table.method')}
+ </dt>
+ <dd>{payment.payment_method?.name ?? '—'}</dd>
+ <dt className="text-muted-foreground">
+ {t('admin.orders.detail.payments_table.state')}
+ </dt>
+ <dd>
+ <StatusBadge status={payment.status} />
+ </dd>
+ <dt className="text-muted-foreground">{t('admin.fields.amount.label')}</dt>
+ <dd className="tabular-nums">
+ <Money amount={payment.amount} currency={currency} />
+ </dd>
+ <dt className="text-muted-foreground">
+ {t('admin.orders.detail.payment_details.transaction_id')}
+ </dt>
+ <dd className="font-mono text-xs break-all">{payment.response_code ?? '—'}</dd>
+ {payment.source_type === 'credit_card' && (
+ <>
+ <CheckRow
+ label={t('admin.orders.detail.payment_details.address_check')}
+ outcome={addressCheck(payment)}
+ code={payment.avs_response}
+ />
+ <CheckRow
+ label={t('admin.orders.detail.payment_details.security_code_check')}
+ outcome={securityCodeCheck(payment)}
+ code={payment.cvv_response_code}
+ message={payment.cvv_response_message}
+ />
+ </>
+ )}
+ </dl>
+ <section className="flex flex-col gap-2">
+ <h3 className="font-medium text-sm">
+ {t('admin.orders.detail.payment_details.captures')}
+ </h3>
+ {captures.length === 0 ? (
+ <p className="text-muted-foreground text-sm">
+ {t('admin.orders.detail.payment_details.captures_empty')}
+ </p>
+ ) : (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>{t('admin.orders.detail.payment_details.captured_at')}</TableHead>
+ <TableHead className="text-right">{t('admin.fields.amount.label')}</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {captures.map((capture) => (
+ <TableRow key={capture.id}>
+ <TableCell>
+ <RelativeTime iso={capture.created_at} />
+ </TableCell>
+ <TableCell className="text-right tabular-nums">
+ <Money amount={capture.amount} currency={currency} />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ )}
+ </section>
+ </DialogBody>
+ {payment.gateway_dashboard_payment_url && (
+ <DialogFooter>
+ <Button variant="outline" asChild>
+ <a
+ href={payment.gateway_dashboard_payment_url}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <ExternalLinkIcon data-icon="inline-start" />
+ {t('admin.orders.detail.payments_table.view_at_gateway', {
+ gateway: payment.payment_method?.name,
+ })}
+ </a>
+ </Button>
+ </DialogFooter>
+ )}
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+function CheckRow({
+ label,
+ outcome,
+ code,
+ message,
+}: {
+ label: string
+ outcome: CheckOutcome
+ code: string | null
+ message?: string | null
+}) {
+ const { t } = useTranslation()
+
+ return (
+ <>
+ <dt className="text-muted-foreground">{label}</dt>
+ <dd className="flex flex-wrap items-center gap-2">
+ <Badge variant={OUTCOME_VARIANTS[outcome]}>
+ {t(`admin.orders.detail.payment_details.check.${outcome}`)}
+ </Badge>
+ {code && (
+ <span className="text-muted-foreground text-xs">
+ {t('admin.orders.detail.payment_details.code', { code })}
+ </span>
+ )}
+ {message && <span className="text-muted-foreground text-xs">{message}</span>}
+ </dd>
+ </>
+ )
+}
diff --git a/packages/dashboard/src/hooks/use-order.ts b/packages/dashboard/src/hooks/use-order.ts
index 1d07ed300e..93146014a3 100644
--- a/packages/dashboard/src/hooks/use-order.ts
+++ b/packages/dashboard/src/hooks/use-order.ts
@@ -22,6 +22,7 @@ export function useOrder(orderId: string) {
'fulfillments.delivery_rates.delivery_method',
'payments',
'payments.payment_method',
+ 'payments.capture_events',
// An order from a split checkout has no payments of its own; what
// it has is a share of each payment made against its group.
'payment_splits',
diff --git a/packages/dashboard/src/hooks/use-seller-ledger.ts b/packages/dashboard/src/hooks/use-seller-ledger.ts
index ae46aeaa68..bcc962d3be 100644
--- a/packages/dashboard/src/hooks/use-seller-ledger.ts
+++ b/packages/dashboard/src/hooks/use-seller-ledger.ts
@@ -105,7 +105,7 @@ export function useOrderGroup(orderGroupId: string | null | undefined) {
queryFn: () =>
adminClient.orderGroups.get(orderGroupId as string, {
fields: ['payments', 'number'],
- expand: ['payments.payment_method'],
+ expand: ['payments.payment_method', 'payments.capture_events'],
}),
enabled: !!orderGroupId,
})
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index e3d3756b60..96933393b8 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -2953,7 +2953,9 @@
"this_order": "هذا الطلب",
"shared_help": "دُفعت مرة واحدة لسلة تضم عدة بائعين. هذا الطلب له حصة منها.",
"load_error": "تعذر تحميل مدفوعات هذا الطلب.",
- "view_at_gateway": "عرض في {{gateway}}"
+ "view_at_gateway": "عرض في {{gateway}}",
+ "view_details": "عرض التفاصيل",
+ "failed_card_checks": "فشل التحقق من البطاقة"
},
"priced_by": "التسعير من {{name}}",
"purchase_order": {
@@ -3003,6 +3005,22 @@
"cbm": "{{value}} م³",
"kg": "{{value}} كجم",
"incomplete": "بعض الأصناف غير مقاسة، لذا هذه الأرقام حد أدنى وليست إجماليًا."
+ },
+ "payment_details": {
+ "title": "الدفعة {{number}}",
+ "description": "ما أبلغت عنه الجهة المصدرة للبطاقة، وكل عملية تحصيل للمبلغ.",
+ "transaction_id": "معرّف المعاملة",
+ "address_check": "التحقق من العنوان",
+ "security_code_check": "التحقق من رمز الأمان",
+ "code": "الرمز {{code}}",
+ "check": {
+ "passed": "ناجح",
+ "failed": "غير ناجح",
+ "not_checked": "لم يتم التحقق"
+ },
+ "captures": "عمليات التحصيل",
+ "captures_empty": "لم يتم تحصيل أي مبلغ بعد.",
+ "captured_at": "تاريخ التحصيل"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 67cb167e4b..2124f553b8 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -2933,7 +2933,9 @@
"this_order": "Diese Bestellung",
"shared_help": "Einmal bezahlt für einen Warenkorb mehrerer Verkäufer. Diese Bestellung hat einen Anteil daran.",
"load_error": "Die Zahlungen für diese Bestellung konnten nicht geladen werden.",
- "view_at_gateway": "In {{gateway}} ansehen"
+ "view_at_gateway": "In {{gateway}} ansehen",
+ "view_details": "Details ansehen",
+ "failed_card_checks": "Kartenprüfung fehlgeschlagen"
},
"priced_by": "Preis von {{name}}",
"purchase_order": {
@@ -2983,6 +2985,22 @@
"cbm": "{{value}} m³",
"kg": "{{value}} kg",
"incomplete": "Einige Artikel sind nicht vermessen. Diese Werte sind daher ein Mindestwert, keine Gesamtsumme."
+ },
+ "payment_details": {
+ "title": "Zahlung {{number}}",
+ "description": "Was der Kartenaussteller gemeldet hat, und jede Erfassung des Betrags.",
+ "transaction_id": "Transaktions-ID",
+ "address_check": "Adressprüfung",
+ "security_code_check": "Prüfung des Sicherheitscodes",
+ "code": "Code {{code}}",
+ "check": {
+ "passed": "Bestanden",
+ "failed": "Nicht bestanden",
+ "not_checked": "Nicht geprüft"
+ },
+ "captures": "Erfassungen",
+ "captures_empty": "Es wurde noch nichts erfasst.",
+ "captured_at": "Erfasst"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 0ffa36a555..cb1bef0c09 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -2933,7 +2933,9 @@
"this_order": "This order",
"shared_help": "Paid once for a basket spanning several sellers. This order has a share of it.",
"load_error": "Could not load the payments for this order.",
- "view_at_gateway": "View at {{gateway}}"
+ "view_at_gateway": "View at {{gateway}}",
+ "view_details": "View details",
+ "failed_card_checks": "Failed card checks"
},
"priced_by": "Priced by {{name}}",
"purchase_order": {
@@ -2983,6 +2985,22 @@
"cbm": "{{value}} CBM",
"kg": "{{value}} kg",
"incomplete": "Some items are not measured, so these figures are a floor rather than a total."
+ },
+ "payment_details": {
+ "title": "Payment {{number}}",
+ "description": "What the card issuer reported, and each capture of the money.",
+ "transaction_id": "Transaction ID",
+ "address_check": "Address check",
+ "security_code_check": "Security code check",
+ "code": "Code {{code}}",
+ "check": {
+ "passed": "Passed",
+ "failed": "Did not pass",
+ "not_checked": "Not checked"
+ },
+ "captures": "Captures",
+ "captures_empty": "Nothing has been captured yet.",
+ "captured_at": "Captured"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.json
index 0cd9c5d8dd..93f7085b48 100644
--- a/packages/dashboard/src/locales/es.json
+++ b/packages/dashboard/src/locales/es.json
@@ -2719,7 +2719,9 @@
"this_order": "Este pedido",
"shared_help": "Pagado una vez por un carrito que abarca varios vendedores. Este pedido tiene una parte de él.",
"load_error": "No se pudieron cargar los pagos de este pedido.",
- "view_at_gateway": "Ver en {{gateway}}"
+ "view_at_gateway": "Ver en {{gateway}}",
+ "view_details": "Ver detalles",
+ "failed_card_checks": "Verificaciones de tarjeta fallidas"
},
"priced_by": "Precio según {{name}}",
"purchase_order": {
@@ -2769,6 +2771,22 @@
"cbm": "{{value}} CBM",
"kg": "{{value}} kg",
"incomplete": "Algunos artículos no están medidos, así que estas cifras son un piso más que un total."
+ },
+ "payment_details": {
+ "title": "Pago {{number}}",
+ "description": "Lo que informó el emisor de la tarjeta y cada captura del importe.",
+ "transaction_id": "ID de transacción",
+ "address_check": "Verificación de dirección",
+ "security_code_check": "Verificación del código de seguridad",
+ "code": "Código {{code}}",
+ "check": {
+ "passed": "Superada",
+ "failed": "No superada",
+ "not_checked": "No verificada"
+ },
+ "captures": "Capturas",
+ "captures_empty": "Aún no se ha capturado nada.",
+ "captured_at": "Capturado"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index d0c3aa466c..828a1c9f85 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -2933,7 +2933,9 @@
"this_order": "Cette commande",
"shared_help": "Payé en une fois pour un panier réparti entre plusieurs vendeurs. Cette commande en détient une part.",
"load_error": "Impossible de charger les paiements de cette commande.",
- "view_at_gateway": "Voir sur {{gateway}}"
+ "view_at_gateway": "Voir sur {{gateway}}",
+ "view_details": "Voir les détails",
+ "failed_card_checks": "Vérifications de carte échouées"
},
"priced_by": "Tarifé par {{name}}",
"purchase_order": {
@@ -2983,6 +2985,22 @@
"cbm": "{{value}} m³",
"kg": "{{value}} kg",
"incomplete": "Certains articles ne sont pas mesurés : ces chiffres sont un minimum, pas un total."
+ },
+ "payment_details": {
+ "title": "Paiement {{number}}",
+ "description": "Ce que l'émetteur de la carte a signalé, et chaque capture du montant.",
+ "transaction_id": "ID de transaction",
+ "address_check": "Vérification de l'adresse",
+ "security_code_check": "Vérification du code de sécurité",
+ "code": "Code {{code}}",
+ "check": {
+ "passed": "Réussie",
+ "failed": "Échouée",
+ "not_checked": "Non vérifiée"
+ },
+ "captures": "Captures",
+ "captures_empty": "Rien n'a encore été capturé.",
+ "captured_at": "Capturé"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index e0d98311b4..4f82b7e588 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -2961,7 +2961,9 @@
"this_order": "To zamówienie",
"shared_help": "Zapłacone raz za koszyk obejmujący kilku sprzedawców. To zamówienie ma w nim udział.",
"load_error": "Nie udało się wczytać płatności tego zamówienia.",
- "view_at_gateway": "Zobacz w {{gateway}}"
+ "view_at_gateway": "Zobacz w {{gateway}}",
+ "view_details": "Zobacz szczegóły",
+ "failed_card_checks": "Nieudana weryfikacja karty"
},
"priced_by": "Cena z {{name}}",
"purchase_order": {
@@ -3011,6 +3013,22 @@
"cbm": "{{value}} m³",
"kg": "{{value}} kg",
"incomplete": "Część towaru nie ma wymiarów, więc te liczby to wartość minimalna, a nie suma."
+ },
+ "payment_details": {
+ "title": "Płatność {{number}}",
+ "description": "Co zgłosił wydawca karty oraz każde pobranie środków.",
+ "transaction_id": "ID transakcji",
+ "address_check": "Weryfikacja adresu",
+ "security_code_check": "Weryfikacja kodu bezpieczeństwa",
+ "code": "Kod {{code}}",
+ "check": {
+ "passed": "Pozytywna",
+ "failed": "Negatywna",
+ "not_checked": "Niesprawdzona"
+ },
+ "captures": "Pobrania środków",
+ "captures_empty": "Nie pobrano jeszcze żadnych środków.",
+ "captured_at": "Pobrano"
}
},
"edit": {
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index fc7faf4674..dfee76232c 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -2925,7 +2925,9 @@
"this_order": "本订单",
"shared_help": "该购物车横跨多个卖家,只支付了一次。本订单占其中一部分。",
"load_error": "无法加载此订单的付款信息。",
- "view_at_gateway": "在 {{gateway}} 中查看"
+ "view_at_gateway": "在 {{gateway}} 中查看",
+ "view_details": "查看详情",
+ "failed_card_checks": "银行卡验证未通过"
},
"priced_by": "定价来自 {{name}}",
"purchase_order": {
@@ -2975,6 +2977,22 @@
"cbm": "{{value}} 立方米",
"kg": "{{value}} 公斤",
"incomplete": "部分商品未量尺寸,因此以上数字是下限而非总量。"
+ },
+ "payment_details": {
+ "title": "付款 {{number}}",
+ "description": "发卡机构的验证结果,以及每一笔资金扣款。",
+ "transaction_id": "交易 ID",
+ "address_check": "地址验证",
+ "security_code_check": "安全码验证",
+ "code": "代码 {{code}}",
+ "check": {
+ "passed": "通过",
+ "failed": "未通过",
+ "not_checked": "未验证"
+ },
+ "captures": "扣款记录",
+ "captures_empty": "尚未扣款。",
+ "captured_at": "扣款时间"
}
},
"edit": {
diff --git a/spree/api/app/controllers/spree/api/v3/admin/order_groups_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/order_groups_controller.rb
index 4a2fa72a4e..52aaa2c059 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/order_groups_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/order_groups_controller.rb
@@ -32,7 +32,7 @@ module Spree
def collection_includes
[
:customer, :ship_address, :bill_address,
- { payments: %i[payment_method source] },
+ { payments: %i[payment_method source capture_events] },
{ orders: %i[market gift_card] }
]
end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb
new file mode 100644
index 0000000000..44c762dabf
--- /dev/null
+++ b/spree/api/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb
@@ -0,0 +1,16 @@
+module Spree
+ module Api
+ module V3
+ module Admin
+ # Serializes Spree::PaymentCaptureEvent — one capture of money a
+ # payment had authorized. A payment captured in parts has one per part.
+ class PaymentCaptureEventSerializer < V3::BaseSerializer
+ attributes created_at: :iso8601, updated_at: :iso8601
+
+ money_attributes :amount
+ typelize amount: [:string, nullable: false]
+ end
+ end
+ end
+ end
+end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/payment_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/payment_serializer.rb
index f1039b0237..538e12da00 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/payment_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/payment_serializer.rb
@@ -14,12 +14,17 @@ module Spree
avs_response: [:string, nullable: true],
cvv_response_code: [:string, nullable: true],
cvv_response_message: [:string, nullable: true],
- gateway_dashboard_payment_url: [:string, nullable: true]
+ gateway_dashboard_payment_url: [:string, nullable: true],
+ avs_risky: [:boolean, comment: 'Whether the card issuer reported that the billing address did not match.'],
+ cvv_risky: [:boolean, comment: 'Whether the card issuer reported that the security code did not match.']
attributes :metadata, :avs_response, :cvv_response_code, :cvv_response_message,
:gateway_dashboard_payment_url,
created_at: :iso8601, updated_at: :iso8601
+ attribute(:avs_risky, &:is_avs_risky?)
+ attribute(:cvv_risky, &:is_cvv_risky?)
+
money_attributes :captured_amount
typelize captured_amount: [:string, nullable: false]
@@ -43,6 +48,10 @@ module Spree
serializer.new(payment.source).to_h
end
+ many :capture_events,
+ resource: proc { Spree.api.admin_payment_capture_event_serializer },
+ if: proc { expand?('capture_events') }
+
one :order,
resource: proc { Spree.api.admin_order_serializer },
if: proc { expand?('order') }
diff --git a/spree/api/lib/spree/api/dependencies.rb b/spree/api/lib/spree/api/dependencies.rb
index e3995d1a09..7eebb78552 100644
--- a/spree/api/lib/spree/api/dependencies.rb
+++ b/spree/api/lib/spree/api/dependencies.rb
@@ -34,7 +34,7 @@ module Spree
catalog_product price_list_product catalog_assignment catalog_quantity_rule catalog_product_term
catalog_order_minimum tax_exemption_certificate admin_user actor seller_team_member product_submission
seller seller_requirement seller_requirement_submission seller_requirement_status commission_rate
- commission_rule commission_line seller_transfer seller_payout seller_balance payment_split address
+ commission_rule commission_line seller_transfer seller_payout seller_balance payment_split payment_capture_event address
channel order_routing_rule product_publication market delivery_method delivery_method_service
stock_location stock_reservation delivery_rate freight_summary freight_summary_line payment_method
credit_card store_credit store_credit_event customer_group payment_source digital_asset digital_link
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb
index 32a976d299..aace145b87 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb
@@ -47,6 +47,22 @@ RSpec.describe Spree::Api::V3::Admin::Orders::PaymentsController, type: :control
expect(json_response['gateway_dashboard_payment_url']).to eq('https://dashboard.example.com/payments/ch_123')
end
+ it 'returns each capture of the payment when expanded' do
+ capture = create(:payment_capture_event, payment: payment, amount: BigDecimal('25.5'))
+
+ get :show, params: { order_id: order_with_payment.prefixed_id, id: payment.prefixed_id, expand: 'capture_events' }, as: :json
+
+ expect(json_response['capture_events']).to include(include('id' => capture.prefixed_id, 'amount' => '25.50'))
+ end
+
+ it 'reports which card checks failed' do
+ payment.update_columns(avs_response: 'Y', cvv_response_code: 'N', cvv_response_message: 'CVV does not match')
+
+ get :show, params: { order_id: order_with_payment.prefixed_id, id: payment.prefixed_id }, as: :json
+
+ expect(json_response).to include('avs_risky' => false, 'cvv_risky' => true)
+ end
+
it 'returns 404 for unknown payment id' do
get :show, params: { order_id: order_with_payment.prefixed_id, id: 'pay_unknown' }, as: :json
diff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rb
index dd64975550..dbb466cd04 100644
--- a/spree/core/app/models/spree/payment.rb
+++ b/spree/core/app/models/spree/payment.rb
@@ -326,10 +326,11 @@ module Spree
true
end
+ # Matches +Payment.risky+: any result other than a match counts, whatever
+ # message the gateway sent with it.
def is_cvv_risky?
return false if cvv_response_code == 'M'
return false if cvv_response_code.nil?
- return false if cvv_response_message.present?
true
end
diff --git a/spree/core/app/models/spree/payment_capture_event.rb b/spree/core/app/models/spree/payment_capture_event.rb
index e237da2294..3f16d542c9 100644
--- a/spree/core/app/models/spree/payment_capture_event.rb
+++ b/spree/core/app/models/spree/payment_capture_event.rb
@@ -4,6 +4,8 @@ module Spree
belongs_to :payment, class_name: 'Spree::Payment'
+ delegate :currency, to: :payment
+
def display_amount
Spree::Money.new(amount, currency: payment.currency)
end
diff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rb
index 63443cb454..a9684fb5ca 100644
--- a/spree/core/spec/models/spree/payment_spec.rb
+++ b/spree/core/spec/models/spree/payment_spec.rb
@@ -995,6 +995,11 @@ describe Spree::Payment, type: :model do
expect(payment.is_cvv_risky?).to eq(true)
end
end
+
+ it 'returns true for a mismatch the gateway described' do
+ payment.assign_attributes(cvv_response_code: 'N', cvv_response_message: 'CVV does not match')
+ expect(payment.is_cvv_risky?).to eq(true)
+ end
end
describe '#editable?' do