From 32006aea3cb20ff73201127be8b9494340505d8d Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 24 Jun 2019 13:22:13 +0200 Subject: [PATCH] feat(admin-ui): Add controls to settle authorized payments Relates to #117 --- admin-ui/src/app/common/generated-types.ts | 13 +++++++++ .../app/data/definitions/order-definitions.ts | 13 +++++++++ .../app/data/providers/order-data.service.ts | 10 +++++-- .../order-detail/order-detail.component.html | 25 ++++++++++++++++- .../order-detail/order-detail.component.ts | 28 +++++++++++++++++-- .../payment-method-detail.component.html | 5 +--- admin-ui/src/i18n-messages/en.json | 4 +++ 7 files changed, 89 insertions(+), 9 deletions(-) diff --git a/admin-ui/src/app/common/generated-types.ts b/admin-ui/src/app/common/generated-types.ts index a23d3345c8..68d15dcde2 100644 --- a/admin-ui/src/app/common/generated-types.ts +++ b/admin-ui/src/app/common/generated-types.ts @@ -3418,6 +3418,13 @@ export type GetOrderQueryVariables = { export type GetOrderQuery = ({ __typename?: 'Query' } & { order: Maybe<({ __typename?: 'Order' } & OrderWithLinesFragment)> }); +export type SettlePaymentMutationVariables = { + id: Scalars['ID'] +}; + + +export type SettlePaymentMutation = ({ __typename?: 'Mutation' } & { settlePayment: Maybe<({ __typename?: 'Payment' } & Pick)> }); + export type AssetFragment = ({ __typename?: 'Asset' } & Pick); export type ProductVariantFragment = ({ __typename?: 'ProductVariant' } & Pick & { taxRateApplied: ({ __typename?: 'TaxRate' } & Pick), taxCategory: ({ __typename?: 'TaxCategory' } & Pick), options: Array<({ __typename?: 'ProductOption' } & Pick)>, facetValues: Array<({ __typename?: 'FacetValue' } & Pick & { facet: ({ __typename?: 'Facet' } & Pick) })>, featuredAsset: Maybe<({ __typename?: 'Asset' } & AssetFragment)>, assets: Array<({ __typename?: 'Asset' } & AssetFragment)>, translations: Array<({ __typename?: 'ProductVariantTranslation' } & Pick)> }); @@ -4185,6 +4192,12 @@ export namespace GetOrder { export type Order = OrderWithLinesFragment; } +export namespace SettlePayment { + export type Variables = SettlePaymentMutationVariables; + export type Mutation = SettlePaymentMutation; + export type SettlePayment = (NonNullable); +} + export namespace Asset { export type Fragment = AssetFragment; } diff --git a/admin-ui/src/app/data/definitions/order-definitions.ts b/admin-ui/src/app/data/definitions/order-definitions.ts index 6b6cb5b37b..9c24275635 100644 --- a/admin-ui/src/app/data/definitions/order-definitions.ts +++ b/admin-ui/src/app/data/definitions/order-definitions.ts @@ -125,3 +125,16 @@ export const GET_ORDER = gql` } ${ORDER_WITH_LINES_FRAGMENT} `; + +export const SETTLE_PAYMENT = gql` + mutation SettlePayment($id: ID!) { + settlePayment(id: $id) { + id + transactionId + amount + method + state + metadata + } + } +`; diff --git a/admin-ui/src/app/data/providers/order-data.service.ts b/admin-ui/src/app/data/providers/order-data.service.ts index 7be41d3c60..b306fc174b 100644 --- a/admin-ui/src/app/data/providers/order-data.service.ts +++ b/admin-ui/src/app/data/providers/order-data.service.ts @@ -1,5 +1,5 @@ -import { GetOrder, GetOrderList } from '../../common/generated-types'; -import { GET_ORDER, GET_ORDERS_LIST } from '../definitions/order-definitions'; +import { GetOrder, GetOrderList, SettlePayment } from '../../common/generated-types'; +import { GET_ORDER, GET_ORDERS_LIST, SETTLE_PAYMENT } from '../definitions/order-definitions'; import { BaseDataService } from './base-data.service'; @@ -18,4 +18,10 @@ export class OrderDataService { getOrder(id: string) { return this.baseDataService.query(GET_ORDER, { id }); } + + settlePayment(id: string) { + return this.baseDataService.mutate(SETTLE_PAYMENT, { + id, + }); + } } diff --git a/admin-ui/src/app/order/components/order-detail/order-detail.component.html b/admin-ui/src/app/order/components/order-detail/order-detail.component.html index e4d84982d5..0aa8cac92f 100644 --- a/admin-ui/src/app/order/components/order-detail/order-detail.component.html +++ b/admin-ui/src/app/order/components/order-detail/order-detail.component.html @@ -4,7 +4,7 @@ -
+
@@ -53,6 +53,29 @@
+ + + + diff --git a/admin-ui/src/app/order/components/order-detail/order-detail.component.ts b/admin-ui/src/app/order/components/order-detail/order-detail.component.ts index 4523196f95..f959df6900 100644 --- a/admin-ui/src/app/order/components/order-detail/order-detail.component.ts +++ b/admin-ui/src/app/order/components/order-detail/order-detail.component.ts @@ -1,9 +1,12 @@ -import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; +import { _ } from 'src/app/core/providers/i18n/mark-for-extraction'; import { BaseDetailComponent } from '../../../common/base-detail.component'; import { Order, OrderWithLines } from '../../../common/generated-types'; +import { NotificationService } from '../../../core/providers/notification/notification.service'; +import { DataService } from '../../../data/providers/data.service'; import { ServerConfigService } from '../../../data/server-config'; @Component({ @@ -15,7 +18,14 @@ import { ServerConfigService } from '../../../data/server-config'; export class OrderDetailComponent extends BaseDetailComponent implements OnInit, OnDestroy { detailForm = new FormGroup({}); - constructor(router: Router, route: ActivatedRoute, serverConfigService: ServerConfigService) { + constructor( + router: Router, + route: ActivatedRoute, + serverConfigService: ServerConfigService, + private changeDetector: ChangeDetectorRef, + private dataService: DataService, + private notificationService: NotificationService, + ) { super(route, router, serverConfigService); } @@ -38,6 +48,20 @@ export class OrderDetailComponent extends BaseDetailComponent { + if (settlePayment) { + if (settlePayment.state === 'Settled') { + this.notificationService.success(_('order.settle-payment-success')); + } else { + this.notificationService.error(_('order.settle-payment-error')); + } + payment.state = settlePayment.state; + this.changeDetector.markForCheck(); + } + }); + } + protected setFormValues(entity: Order.Fragment): void { // empty } diff --git a/admin-ui/src/app/settings/components/payment-method-detail/payment-method-detail.component.html b/admin-ui/src/app/settings/components/payment-method-detail/payment-method-detail.component.html index e0a00248c6..6ff1093a47 100644 --- a/admin-ui/src/app/settings/components/payment-method-detail/payment-method-detail.component.html +++ b/admin-ui/src/app/settings/components/payment-method-detail/payment-method-detail.component.html @@ -46,10 +46,7 @@ [for]="arg.name" *ngIf="arg.type === ConfigArgType.BOOLEAN" > -
- - -
+ diff --git a/admin-ui/src/i18n-messages/en.json b/admin-ui/src/i18n-messages/en.json index 5d9c13a631..aa1353bd73 100644 --- a/admin-ui/src/i18n-messages/en.json +++ b/admin-ui/src/i18n-messages/en.json @@ -411,9 +411,13 @@ "order-code": "Order code", "payment-metadata": "Payment metadata", "payment-method": "Payment method", + "payment-state": "State", "product-name": "Product name", "product-sku": "SKU", "quantity": "Quantity", + "settle-payment": "Settle payment", + "settle-payment-error": "Could not settle payment", + "settle-payment-success": "Sucessfully settled payment", "shipping": "Shipping", "shipping-address": "Shipping address", "state": "State",
{{ 'order.payment-state' | translate }} + {{ payment.state }} + + + + + + + + +
{{ 'order.payment-method' | translate }} {{ payment.method }}