Skip to content

Commit

Permalink
feat: Order recurrence (subscription support)
Browse files Browse the repository at this point in the history
  • Loading branch information
shauke committed Jun 24, 2024
1 parent 9d3bac5 commit 48251ed
Show file tree
Hide file tree
Showing 36 changed files with 588 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>
<a
[routerLink]="['/account/requisitions/buyer/' + req.id, { status: 'PENDING' }]"
data-testing-id="requisition-number"
>{{ req.requisitionNo }}</a
>{{ req.requisitionNo ? req.requisitionNo : req.recurringOrderDocumentNo }}</a
>
</strong>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RequisitionApproval, RequisitionUserBudget } from './requisition.model'
export interface RequisitionBaseData extends BasketBaseData {
requisitionNo: string;
orderNo?: string;
recurringOrderDocumentNo?: string;
order?: {
itemId: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class RequisitionMapper {
id: data.id,
requisitionNo: data.requisitionNo,
orderNo: data.orderNo,
recurringOrderDocumentNo: data.recurringOrderDocumentNo,
creationDate: data.creationDate,
userBudget: this.fromUserBudgets(data.userBudgets, data.purchaseCurrency),
lineItemCount: data.lineItemCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type RequisitionBasket = Omit<AbstractBasket<LineItem>, 'approval'>;
export interface Requisition extends RequisitionBasket {
requisitionNo: string;
orderNo?: string;
recurringOrderDocumentNo?: string;
creationDate: number;
lineItemCount: number;

Expand Down
5 changes: 5 additions & 0 deletions src/app/core/facades/checkout.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
updateBasketAddress,
updateBasketCostCenter,
updateBasketItem,
updateBasketRecurrence,
updateBasketShippingMethod,
updateConcardisCvcLastUpdated,
} from 'ish-core/store/customer/basket';
Expand Down Expand Up @@ -143,6 +144,10 @@ export class CheckoutFacade {
this.store.dispatch(updateBasketCostCenter({ costCenter }));
}

updateBasketRecurrence(recurrence: any) {

Check failure on line 147 in src/app/core/facades/checkout.facade.ts

View workflow job for this annotation

GitHub Actions / GitBash

Unexpected any. Specify a different type

Check failure on line 147 in src/app/core/facades/checkout.facade.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Unexpected any. Specify a different type

Check failure on line 147 in src/app/core/facades/checkout.facade.ts

View workflow job for this annotation

GitHub Actions / Powershell

Unexpected any. Specify a different type

Check failure on line 147 in src/app/core/facades/checkout.facade.ts

View workflow job for this annotation

GitHub Actions / Quality

Unexpected any. Specify a different type
this.store.dispatch(updateBasketRecurrence({ recurrence }));
}

updateBasketExternalOrderReference(externalOrderReference: string) {
this.store.dispatch(updateBasket({ update: { externalOrderReference } }));
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/models/basket/basket.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-in
import { PaymentMethodBaseData } from 'ish-core/models/payment-method/payment-method.interface';
import { PaymentData } from 'ish-core/models/payment/payment.interface';
import { PriceItemData } from 'ish-core/models/price-item/price-item.interface';
import { Recurrence } from 'ish-core/models/recurrence/recurrence.model';
import { ShippingMethodData } from 'ish-core/models/shipping-method/shipping-method.interface';

export interface BasketBaseData {
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface BasketBaseData {
firstName: string;
lastName: string;
};
recurrence?: Recurrence;
}

export interface BasketIncludedData {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/basket/basket.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class BasketMapper {
user: data.buyer,
externalOrderReference: data.externalOrderReference,
messageToMerchant: data.messageToMerchant,
recurrence: data.recurrence,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/core/models/basket/basket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BasketTotal } from 'ish-core/models/basket-total/basket-total.model';
import { BasketValidationResultType } from 'ish-core/models/basket-validation/basket-validation.model';
import { LineItem, LineItemView } from 'ish-core/models/line-item/line-item.model';
import { Payment } from 'ish-core/models/payment/payment.model';
import { Recurrence } from 'ish-core/models/recurrence/recurrence.model';
import { ShippingMethod } from 'ish-core/models/shipping-method/shipping-method.model';

export interface AbstractBasket<T> {
Expand Down Expand Up @@ -36,6 +37,7 @@ export interface AbstractBasket<T> {
};
externalOrderReference?: string;
messageToMerchant?: string;
recurrence?: Recurrence;
}

export type Basket = AbstractBasket<LineItem>;
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/models/recurrence/recurrence.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Recurrence {
interval: string;
startDate: string;
endDate?: string;
repetitions?: number;
}
4 changes: 3 additions & 1 deletion src/app/core/services/basket/basket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BasketValidation, BasketValidationScopeType } from 'ish-core/models/bas
import { BasketBaseData, BasketData } from 'ish-core/models/basket/basket.interface';
import { BasketMapper } from 'ish-core/models/basket/basket.mapper';
import { Basket } from 'ish-core/models/basket/basket.model';
import { Recurrence } from 'ish-core/models/recurrence/recurrence.model';
import { ShippingMethodData } from 'ish-core/models/shipping-method/shipping-method.interface';
import { ShippingMethodMapper } from 'ish-core/models/shipping-method/shipping-method.mapper';
import { ShippingMethod } from 'ish-core/models/shipping-method/shipping-method.model';
Expand All @@ -31,7 +32,8 @@ export type BasketUpdateType =
| { costCenter: string }
| { externalOrderReference: string }
| { invoiceToAddress: string }
| { messageToMerchant: string };
| { messageToMerchant: string }
| { recurrence: Recurrence };

/**
* The Basket Service handles the interaction with the 'baskets' REST API.
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/store/customer/basket/basket.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export const updateBasketCostCenter = createAction(
'[Basket] Assign a Cost Center at Basket ',
payload<{ costCenter: string }>()
);

export const updateBasketRecurrence = createAction(
'[Basket] Set the Recurrence Information at Basket ',
payload<{ recurrence: any }>()

Check failure on line 74 in src/app/core/store/customer/basket/basket.actions.ts

View workflow job for this annotation

GitHub Actions / GitBash

Unexpected any. Specify a different type

Check failure on line 74 in src/app/core/store/customer/basket/basket.actions.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Unexpected any. Specify a different type

Check failure on line 74 in src/app/core/store/customer/basket/basket.actions.ts

View workflow job for this annotation

GitHub Actions / Powershell

Unexpected any. Specify a different type

Check failure on line 74 in src/app/core/store/customer/basket/basket.actions.ts

View workflow job for this annotation

GitHub Actions / Quality

Unexpected any. Specify a different type
);

export const addMessageToMerchant = createAction(
'[Basket] Message to Merchant',
payload<{ messageToMerchant: string }>()
Expand Down
12 changes: 12 additions & 0 deletions src/app/core/store/customer/basket/basket.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
updateBasket,
updateBasketCostCenter,
updateBasketFail,
updateBasketRecurrence,
updateBasketShippingMethod,
} from './basket.actions';
import { getCurrentBasket, getCurrentBasketId } from './basket.selectors';
Expand Down Expand Up @@ -211,6 +212,17 @@ export class BasketEffects {
)
);

/**
* Sets the recurrence at the current basket.
*/
updateBasketRecurrence$ = createEffect(() =>
this.actions$.pipe(
ofType(updateBasketRecurrence),
mapToPayloadProperty('recurrence'),
map(recurrence => updateBasket({ update: { recurrence } }))
)
);

/**
* Sets a message to merchant at the current basket.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div id="order-recurrence">
<div>
<input
type="radio"
id="order_recurrence_single"
name="order_recurrence"
value="single-order"
class="form-check-input"
[checked]="!recurrence"
(change)="updateOrderRecurrence(null)"
/>
<label class="form-check-label" for="order_recurrence_single">One-time purchase</label>
</div>
<div>
<input
type="radio"
id="order_recurrence_recurring"
name="order_recurrence"
value="recurring-order"
class="form-check-input"
[checked]="!!recurrence"
(change)="updateOrderRecurrence(defaultRecurrence)"
/>
<label class="form-check-label" for="order_recurrence_recurring">Recurring order</label>
</div>
<div *ngIf="!!recurrence" class="mt-3">
<form [formGroup]="form">
<formly-form [form]="form" [fields]="fields" [model]="model" />
</form>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import 'variables';

#order-recurrence {
padding: ($space-default * 0.5) ($space-default * 1.5);
margin: ($space-default * 1) ($space-default * -1.5);
background-color: $white;
}

#order-recurrence-configuration {
height: 100px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { BasketOrderRecurrenceEditComponent } from './basket-order-recurrence-edit.component';

describe('Basket Order Recurrence Edit Component', () => {
let component: BasketOrderRecurrenceEditComponent;
let fixture: ComponentFixture<BasketOrderRecurrenceEditComponent>;
let element: HTMLElement;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [BasketOrderRecurrenceEditComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(BasketOrderRecurrenceEditComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
});

it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});
});
Loading

0 comments on commit 48251ed

Please sign in to comment.