Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ad 375 #41

Merged
merged 27 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e0532ae
AD-375 Select delivery method during Apple Express Pay
pjaneta Feb 19, 2025
cf54c7d
Update package.json
pjaneta Feb 19, 2025
0785ea4
AD-375 Select delivery method during Apple Express Pay - Update apple…
pjaneta Feb 20, 2025
6866424
Update package.json
pjaneta Feb 20, 2025
8e41927
AD-375 Select delivery method during Apple Express Pay - change to ca…
pjaneta Feb 20, 2025
a2a0f3b
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 20, 2025
23f6c33
Update package.json
pjaneta Feb 20, 2025
050cf98
AD-375 Select delivery method during Apple Express Pay - change to ca…
pjaneta Feb 20, 2025
53d8b77
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 20, 2025
f042275
AD-375 Select delivery method during Apple Express Pay - pdp url sele…
pjaneta Feb 20, 2025
a991f99
Update package.json
pjaneta Feb 20, 2025
78687d8
AD-375 Select delivery method during Apple Express Pay - cart init fix
pjaneta Feb 21, 2025
f17f1dc
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 21, 2025
abc4315
Update package.json
pjaneta Feb 21, 2025
ce73aba
AD-375 Select delivery method during Apple Express Pay - handlers ref…
pjaneta Feb 24, 2025
c05291c
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 24, 2025
d0a8a21
Update package.json
pjaneta Feb 24, 2025
4ea4f62
AD-375 Select delivery method during Apple Express Pay - cart page fix
pjaneta Feb 24, 2025
bfaea56
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 24, 2025
728bc7f
Update package.json
pjaneta Feb 24, 2025
d41d6dc
AD-375 Select delivery method during Apple Express Pay - refactor
pjaneta Feb 24, 2025
4eb5cac
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 24, 2025
a3872da
AD-375 Select delivery method during Apple Express Pay - add checkout…
pjaneta Feb 25, 2025
762806d
Update package.json
pjaneta Feb 25, 2025
35801e1
Update package.json
pjaneta Feb 26, 2025
a2c5614
Merge branch 'main' into feature/AD-375
pjaneta Feb 26, 2025
cf8489d
Merge remote-tracking branch 'origin/feature/AD-375' into feature/AD-375
pjaneta Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,8 @@
}
}
}
},
"cli": {
"analytics": false
}
}
2 changes: 1 addition & 1 deletion projects/adyen/adyen-spartacus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adyen/adyen-spartacus",
"version": "1.1.4",
"version": "1.1.5",
"schematics": "./schematics/collection.json",
"peerDependencies": {
"@angular/common": "^17.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
ApplePayExpressRequest,
GooglePayExpressCartRequest,
GooglePayExpressRequest,
PlaceOrderRequest,
PlaceOrderResponse
} from "../models/occ.order.models";
Expand All @@ -20,11 +20,11 @@ export class AdyenOrderConnector {
return this.adapter.cancelPayment(userId, cartId, orderCode);
}

placeGoogleExpressOrderCart(userId: string, cartId: string, request: GooglePayExpressCartRequest): Observable<PlaceOrderResponse> {
return this.adapter.placeGoogleExpressOrderCart(userId, cartId, request);
placeGoogleExpressOrderCart(userId: string, cartId: string, request: GooglePayExpressRequest, isPDP: boolean): Observable<PlaceOrderResponse> {
return this.adapter.placeGoogleExpressOrderCart(userId, cartId, request, isPDP);
}

placeAppleExpressOrder(userId: string, cartId: string, request: ApplePayExpressRequest): Observable<PlaceOrderResponse> {
return this.adapter.placeAppleExpressOrder(userId, cartId, request);
placeAppleExpressOrder(userId: string, cartId: string, request: ApplePayExpressRequest, isPDP: boolean): Observable<PlaceOrderResponse> {
return this.adapter.placeAppleExpressOrder(userId, cartId, request, isPDP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { PaymentAction,PaymentResponseData } from "@adyen/adyen-web";
import { Order } from '@spartacus/order/root';

export interface ApplePayExpressRequest {
cartId?: string;
applePayDetails: any;
addressData: any;
productCode?: string;
}

export interface GooglePayExpressCartRequest {
export interface GooglePayExpressRequest {
googlePayDetails: any;
addressData: any;
productCode?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {OccEndpointsService} from '@spartacus/core';
import {Observable} from 'rxjs';
import {
ApplePayExpressRequest,
GooglePayExpressCartRequest,
GooglePayExpressRequest,
PlaceOrderRequest,
PlaceOrderResponse
} from "../../models/occ.order.models";
Expand Down Expand Up @@ -45,8 +45,8 @@ export class OccAdyenOrderAdapter {
});
}

public placeGoogleExpressOrderCart(userId: string, cartId: string, orderData: GooglePayExpressCartRequest): Observable<PlaceOrderResponse> {
return this.http.post<PlaceOrderResponse>(orderData.cartId ? this.getPlaceGoogleExpressOrderEndpointProduct(userId, cartId) : this.getPlaceGoogleExpressOrderEndpointCart(userId, cartId), orderData);
public placeGoogleExpressOrderCart(userId: string, cartId: string, orderData: GooglePayExpressRequest, isPDP: boolean): Observable<PlaceOrderResponse> {
return this.http.post<PlaceOrderResponse>(isPDP ? this.getPlaceGoogleExpressOrderEndpointProduct(userId, cartId) : this.getPlaceGoogleExpressOrderEndpointCart(userId, cartId), orderData);
}

protected getPlaceGoogleExpressOrderEndpointCart(userId: string, cartId: string): string {
Expand All @@ -67,8 +67,8 @@ export class OccAdyenOrderAdapter {
});
}

public placeAppleExpressOrder(userId: string, cartId: string, orderData: ApplePayExpressRequest): Observable<PlaceOrderResponse> {
return this.http.post<PlaceOrderResponse>(orderData.productCode ? this.getPlaceAppleExpressOrderEndpointProduct(userId, cartId) : this.getPlaceAppleExpressOrderEndpointCart(userId, cartId), orderData);
public placeAppleExpressOrder(userId: string, cartId: string, orderData: ApplePayExpressRequest, isPDP: boolean): Observable<PlaceOrderResponse> {
return this.http.post<PlaceOrderResponse>(isPDP ? this.getPlaceAppleExpressOrderEndpointProduct(userId, cartId) : this.getPlaceAppleExpressOrderEndpointCart(userId, cartId), orderData);
}

protected getPlaceAppleExpressOrderEndpointCart(userId: string, cartId: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ export class CheckoutAdyenConfigurationReloadEvent extends CheckoutAdyenConfigur
}
}

export class ExpressCheckoutSuccessfulEvent extends CheckoutEvent {
readonly type = 'ExpressCheckoutSuccessfulEvent';
constructor() {
super();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {ApplePay, SubmitData, UIElement} from "@adyen/adyen-web";
import {AdyenCheckout, AdyenCheckoutError} from '@adyen/adyen-web/auto';
import {AdyenExpressConfigData} from "../../core/models/occ.config.models";
import {AdyenExpressOrderService} from "../../service/adyen-express-order.service";
import {Product, RoutingService,} from '@spartacus/core';
import {Subscription} from 'rxjs';
import {ActiveCartFacade} from '@spartacus/cart/base/root';
import {EventService, Product, RoutingService, UserIdService,} from '@spartacus/core';
import {ActiveCartFacade, Cart, DeliveryMode, MultiCartFacade} from '@spartacus/cart/base/root';
import {getAdyenExpressCheckoutConfig} from "../adyenCheckoutConfig.util";
import {ExpressPaymentBase} from "../base/express-payment-base";
import {AdyenCartService} from "../../service/adyen-cart-service";

@Component({
selector: 'cx-apple-express-payment',
Expand All @@ -16,9 +17,7 @@ import {getAdyenExpressCheckoutConfig} from "../adyenCheckoutConfig.util";
templateUrl: './apple-express-payment.component.html',
styleUrls: ['./apple-express-payment.component.css']
})
export class AppleExpressPaymentComponent implements OnInit, OnDestroy{

protected subscriptions = new Subscription();
export class AppleExpressPaymentComponent extends ExpressPaymentBase implements OnInit, OnDestroy {

@Input()
product: Product;
Expand All @@ -34,16 +33,18 @@ export class AppleExpressPaymentComponent implements OnInit, OnDestroy{
protected adyenOrderService: AdyenExpressOrderService,
protected routingService: RoutingService,
protected activeCartFacade: ActiveCartFacade,
) {}
protected override multiCartService: MultiCartFacade,
protected override userIdService: UserIdService,
protected override adyenCartService: AdyenCartService,
protected override eventService: EventService
) {
super(multiCartService, userIdService, activeCartFacade, adyenCartService, eventService)
}

ngOnInit(): void {
this.setupAdyenCheckout(this.configuration)
}

ngOnDestroy(): void {
this.subscriptions.unsubscribe();
if(this.applePay) this.applePay.unmount();
}

private async setupAdyenCheckout(config: AdyenExpressConfigData) {
const adyenCheckout = await AdyenCheckout(getAdyenExpressCheckoutConfig(config));
Expand All @@ -57,6 +58,7 @@ export class AppleExpressPaymentComponent implements OnInit, OnDestroy{
merchantId: config.applePayMerchantId,
merchantName: config.applePayMerchantName
},
isExpress: true,
// Button config
buttonType: "check-out",
buttonColor: "black",
Expand All @@ -65,6 +67,39 @@ export class AppleExpressPaymentComponent implements OnInit, OnDestroy{
"name",
"email"
],
onShippingContactSelected: (resolve, reject, event) => {
const mappingFunction = (cart: Cart, deliveryModes: DeliveryMode[]): any => {
return {
newTotal: {
label: config.applePayMerchantName,
type: 'final',
amount: cart.totalPriceWithTax!.value!.toString()
},
newShippingMethods: deliveryModes.map((mode) => ({
identifier: mode.code!,
label: mode.name || "",
detail: mode.description || "",
amount: mode.deliveryCost!.value!.toString()
}))
}
}
if (event.shippingContact) {
const address = {postalCode: event.shippingContact.postalCode!, countryCode: event.shippingContact.countryCode!}
this.handleShippingContactSelected<any>(address, this.product, mappingFunction, resolve, reject)
}
},
onShippingMethodSelected: (resolve, reject, event) => {
const mappingFunction = (cart: Cart): any => {
return {
newTotal: {
label: config.applePayMerchantName,
type: 'final',
amount: cart.totalPriceWithTax!.value!.toString()
}
}
}
this.setDeliveryMode<any>(event.shippingMethod.identifier, this.product, mappingFunction, resolve, reject);
},
onSubmit: (state, element: UIElement, actions) => this.handleOnSubmit(state, actions),
onAuthorized: (paymentData, actions) => {
this.authorizedPaymentData = paymentData;
Expand All @@ -78,29 +113,42 @@ export class AppleExpressPaymentComponent implements OnInit, OnDestroy{
}

private handleOnSubmit(state: SubmitData, actions: any) {
this.adyenOrderService.adyenPlaceAppleExpressOrder(state.data, this.authorizedPaymentData, this.product).subscribe(
result => {
if (result?.success) {
if (result.executeAction && result.paymentsAction !== undefined) {
this.applePay.handleAction(result.paymentsAction);
if(!!this.cartId){
this.adyenOrderService.adyenPlaceAppleExpressOrder(state.data, this.authorizedPaymentData, this.product, this.cartId).subscribe(
result => {
if (result?.success) {
if (result.executeAction && result.paymentsAction !== undefined) {
this.applePay.handleAction(result.paymentsAction);
} else {
this.onSuccess();
}
} else {
this.onSuccess();
console.error(result?.error);
actions.reject();
}
} else {
console.error(result?.error);
actions.resolve({resultCode: 'Authorised'});
},
error => {
console.error(error);
actions.reject();
}
actions.resolve({ resultCode: 'Authorised' });
},
error => {
console.error(error);
actions.reject();
}
);
);
} else {
console.error("Undefined cart id")
}

}

handleError(error: AdyenCheckoutError) {
}
handleError(error: AdyenCheckoutError) {}

onSuccess(): void {
this.routingService.go({ cxRoute: 'orderConfirmation' });
this.routingService.go({cxRoute: 'orderConfirmation'});
}

override ngOnDestroy(): void {
super.ngOnDestroy()
this.subscriptions.unsubscribe();
if (this.applePay) this.applePay.unmount();
}
}
Loading