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 50 #325

Merged
merged 25 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ea3180
AD-46 [BE][Express checkout] PDP controller
pjaneta Oct 9, 2023
813b7fd
AD-47 [BE][Express checkout] Cart controller
pjaneta Oct 9, 2023
a422081
AD-48 [BE][Express checkout] Create cart for product from PDP
pjaneta Oct 13, 2023
53920a4
AD-51 [BE][Express checkout] Backend mechanism for express checkout
pjaneta Oct 18, 2023
2b6e8ed
AD-49 [FE][Express checkout] Add ApplePayExpress button on cart page
pjaneta Oct 24, 2023
52543da
AD-50 [FE][Express checkout] Add ApplePayExpress button on PDP + BE f…
pjaneta Oct 26, 2023
413148d
AD-46 [BE][Express checkout] PDP controller
pjaneta Oct 9, 2023
8fa9a51
AD-47 [BE][Express checkout] Cart controller
pjaneta Oct 9, 2023
8932e99
AD-48 [BE][Express checkout] Create cart for product from PDP
pjaneta Oct 13, 2023
31c98b1
AD-51 [BE][Express checkout] Backend mechanism for express checkout
pjaneta Oct 18, 2023
fd8fb7b
AD-49 [FE][Express checkout] Add ApplePayExpress button on cart page
pjaneta Oct 24, 2023
fec2ac6
AD-50 [FE][Express checkout] Add ApplePayExpress button on PDP + BE f…
pjaneta Oct 26, 2023
2a63571
Merge remote-tracking branch 'adyen-origin/feature/AD-50' into featur…
pjaneta Nov 7, 2023
8c965af
AD-49 [FE][Express checkout] Add ApplePayExpress button on cart page …
pjaneta Nov 9, 2023
2e5e43a
Merge branch 'adyen-develop' into feature/AD-50
pjaneta Nov 9, 2023
468e0a5
AD-50 Implementation with known apple data model
pjaneta Nov 14, 2023
0faaf76
AD-50 Address saving and FE fixes
pjaneta Nov 15, 2023
d2771ca
AD-50 adyen_express_checkout error messages and onSubmit fixes
pjaneta Nov 16, 2023
ef4900f
AD-50 set user in session
pjaneta Nov 16, 2023
7ff469f
AD-50 fix emailAddress, add cart recalculation
pjaneta Nov 16, 2023
fda88e4
AD-50 set user in session
pjaneta Nov 17, 2023
252290e
AD-50 add user login
pjaneta Nov 17, 2023
3a911c3
AD-50 add user login
pjaneta Nov 17, 2023
f410926
AD-50 save express checkout guid in session
pjaneta Nov 20, 2023
667c33d
AD-50 Styling + refactor
pjaneta Nov 20, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.adyen.v6.controllers.checkout;

import com.adyen.model.checkout.PaymentsResponse;
import com.adyen.v6.facades.AdyenExpressCheckoutFacade;
import com.adyen.v6.request.ApplePayExpressCartRequest;
import com.adyen.v6.request.ApplePayExpressPDPRequest;
import de.hybris.platform.acceleratorstorefrontcommons.constants.WebConstants;
import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy;
import de.hybris.platform.servicelayer.session.SessionService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class AdyenApplePayExpressCheckoutController {
private static final Logger LOG = Logger.getLogger(AdyenApplePayExpressCheckoutController.class);

@Autowired
private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade;

@Autowired
private SessionService sessionService;

@Autowired
private GUIDCookieStrategy guidCookieStrategy;

@PostMapping("/expressCheckout/applePayPDP")
public ResponseEntity applePayExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressPDPRequest applePayExpressPDPRequest) throws Exception {

PaymentsResponse paymentsResponse = adyenExpressCheckoutFacade.expressPDPCheckout(applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(),
applePayExpressPDPRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressPDPRequest.getAdyenApplePayMerchantName(),
applePayExpressPDPRequest.getApplePayToken(), request);

guidCookieStrategy.setCookie(request, response);
sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE);

return new ResponseEntity<>(paymentsResponse, HttpStatus.OK);
}

@PostMapping("/expressCheckout/cart")
public ResponseEntity cartExpressCheckout(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressCartRequest applePayExpressCartRequest) throws Exception {

PaymentsResponse paymentsResponse = adyenExpressCheckoutFacade.expressCartCheckout(applePayExpressCartRequest.getAddressData(),
applePayExpressCartRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressCartRequest.getAdyenApplePayMerchantName(),
applePayExpressCartRequest.getApplePayToken(), request);

guidCookieStrategy.setCookie(request, response);
sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE);

return new ResponseEntity<>(paymentsResponse, HttpStatus.OK);
}

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(value = Exception.class)
public String adyenComponentExceptionHandler(Exception e) {
LOG.error("Exception during ApplePayExpress processing", e);
return "Exception during ApplePayExpress processing";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.adyen.v6.request;

import de.hybris.platform.commercefacades.user.data.AddressData;

import java.io.Serializable;

public class ApplePayExpressCartRequest implements Serializable {
private AddressData addressData;
private String adyenApplePayMerchantName;
private String adyenApplePayMerchantIdentifier;
private String applePayToken;

public AddressData getAddressData() {
return addressData;
}

public void setAddressData(AddressData addressData) {
this.addressData = addressData;
}

public String getAdyenApplePayMerchantName() {
return adyenApplePayMerchantName;
}

public void setAdyenApplePayMerchantName(String adyenApplePayMerchantName) {
this.adyenApplePayMerchantName = adyenApplePayMerchantName;
}

public String getAdyenApplePayMerchantIdentifier() {
return adyenApplePayMerchantIdentifier;
}

public void setAdyenApplePayMerchantIdentifier(String adyenApplePayMerchantIdentifier) {
this.adyenApplePayMerchantIdentifier = adyenApplePayMerchantIdentifier;
}

public String getApplePayToken() {
return applePayToken;
}

public void setApplePayToken(String applePayToken) {
this.applePayToken = applePayToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.adyen.v6.request;

import de.hybris.platform.commercefacades.user.data.AddressData;

import java.io.Serializable;

public class ApplePayExpressPDPRequest implements Serializable {
private String productCode;
private AddressData addressData;
private String adyenApplePayMerchantName;
private String adyenApplePayMerchantIdentifier;
private String applePayToken;

public String getProductCode() {
return productCode;
}

public void setProductCode(String productCode) {
this.productCode = productCode;
}

public AddressData getAddressData() {
return addressData;
}

public void setAddressData(AddressData addressData) {
this.addressData = addressData;
}

public String getAdyenApplePayMerchantName() {
return adyenApplePayMerchantName;
}

public void setAdyenApplePayMerchantName(String adyenApplePayMerchantName) {
this.adyenApplePayMerchantName = adyenApplePayMerchantName;
}

public String getAdyenApplePayMerchantIdentifier() {
return adyenApplePayMerchantIdentifier;
}

public void setAdyenApplePayMerchantIdentifier(String adyenApplePayMerchantIdentifier) {
this.adyenApplePayMerchantIdentifier = adyenApplePayMerchantIdentifier;
}

public String getApplePayToken() {
return applePayToken;
}

public void setApplePayToken(String applePayToken) {
this.applePayToken = applePayToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ div#section_break {
position:relative !important;
max-height: 280px;
}

.adyen-checkout__applepay__button {
width: 100% !important;
border-radius: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
var AdyenExpressCheckoutHybris = (function() {
'use strict';

var ErrorMessages = {
PaymentCancelled: 'checkout.error.authorization.payment.cancelled',
PaymentError: 'checkout.error.authorization.payment.error',
PaymentNotAvailable: 'checkout.summary.component.notavailable',
TermsNotAccepted: 'checkout.error.terms.not.accepted'
};

return {

adyenConfig: {
merchantName: null,
merchantId: null,
pageType: null,
productCode: null
},

initiateCheckout: async function(initConfig) {
const configuration = {
...initConfig,
analytics: {
enabled: false // Set to false to not send analytics data to Adyen.
},
risk: {
enabled: false
},
onError: (error, component) => {
console.error("Checkout error occured");
},
};

return await AdyenCheckout(configuration);
},
initiateApplePayExpress: async function(params, config) {
var checkoutPromise = this.initiateCheckout(config);
const {
amount,
countryCode,
applePayMerchantIdentifier,
applePayMerchantName,
pageType,
productCode
} = params;

const applePayNode = document.getElementById('adyen-component-button-container');

this.adyenConfig.merchantName = applePayMerchantName;
this.adyenConfig.merchantId = applePayMerchantIdentifier;
this.adyenConfig.pageType = pageType;
this.adyenConfig.productCode = productCode;

const applePayConfiguration = {
//onValidateMerchant is required if you're using your own Apple Pay certificate
onValidateMerchant: (resolve, reject, validationURL) => {
resolve();
}
};
checkoutPromise.then((checkout) => {
var applePayComponent = checkout.create("applepay", {
amount: {
currency: amount.currency,
value: amount.value
},
configuration: {
merchantName: applePayMerchantName,
merchantId: applePayMerchantIdentifier
},
// Button config
buttonType: "check-out",
buttonColor: "black",
requiredShippingContactFields: [
"postalAddress",
"name",
"email"
],
//might be used to recalculate cart with shipping method
// onShippingContactSelected: function(resolve, reject, event){
//
// var shippingMethodUpdate = {
// newTotal: {
// amount: amount.value
// }
// }
// resolve(shippingMethodUpdate);
// },
onClick: function(resolve, reject) {
resolve();
},
onSubmit: function(state, component) {
// empty to block session flow, submit logic done in onAuthorized
},
onAuthorized: (resolve, reject, event) => {
var data = this.prepareData(event);
this.makePayment(data, resolve, reject);
}
});
applePayComponent.isAvailable()
.then(function() {
applePayComponent.mount(applePayNode);
})
.catch(function(e) {
// Apple Pay is not available
console.log('Something went wrong trying to mount the Apple Pay component');
});
})
},
makePayment: function(data, resolve, reject) {
$.ajax({
url: this.getUrl(),
type: "POST",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
success: function(response) {
try {
if (response.resultCode && (response.resultCode === 'Authorised' || response.resultCode === 'RedirectShopper')) {
resolve();
AdyenExpressCheckoutHybris.handleResult(response, false);
} else {
reject();
AdyenExpressCheckoutHybris.handleResult(ErrorMessages.PaymentError, true);
}
} catch (e) {
reject();
AdyenExpressCheckoutHybris.handleResult(ErrorMessages.PaymentError, true);
}
},
error: function(xmlHttpResponse, exception) {
reject();
var responseMessage = xmlHttpResponse.responseJSON;
if (xmlHttpResponse.status === 400) {
AdyenExpressCheckoutHybris.handleResult(responseMessage, true);
} else {
console.log('Error on makePayment');
AdyenExpressCheckoutHybris.handleResult(ErrorMessages.PaymentError, true);
}
}
})
},
handleResult: function(data, error) {
if (error) {
document.querySelector("#resultData").value = data;
document.querySelector("#isResultError").value = error;
} else {
document.querySelector("#resultData").value = JSON.stringify(data);
}
document.querySelector("#handleComponentResultForm").submit();
},
prepareData: function(event) {
if (this.adyenConfig.pageType === 'PDP') {
return {
productCode: this.adyenConfig.productCode,
adyenApplePayMerchantName: this.adyenConfig.merchantName,
adyenApplePayMerchantIdentifier: this.adyenConfig.merchantId,
applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),
addressData: {
email: event.payment.shippingContact.emailAddress,
firstName: event.payment.shippingContact.givenName,
lastName: event.payment.shippingContact.familyName,
line1: event.payment.shippingContact.addressLines[0],
line2: event.payment.shippingContact.addressLines[1],
postalCode: event.payment.shippingContact.postalCode,
town: event.payment.shippingContact.locality,
country: {
isocode: event.payment.shippingContact.countryCode,
name: event.payment.shippingContact.country
}
}
}
}
if (this.adyenConfig.pageType === 'cart') {
return {
adyenApplePayMerchantName: this.adyenConfig.merchantName,
adyenApplePayMerchantIdentifier: this.adyenConfig.merchantId,
applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),
addressData: {
email: event.payment.shippingContact.emailAddress,
firstName: event.payment.shippingContact.givenName,
lastName: event.payment.shippingContact.familyName,
line1: event.payment.shippingContact.addressLines[0],
line2: event.payment.shippingContact.addressLines[1],
postalCode: event.payment.shippingContact.postalCode,
town: event.payment.shippingContact.locality,
country: {
isocode: event.payment.shippingContact.countryCode,
name: event.payment.shippingContact.country
}
}
}
}
console.error('unknown page type')
return {};
},
getUrl: function() {
if (this.adyenConfig.pageType === 'PDP') {
return ACC.config.encodedContextPath + '/expressCheckout/applePayPDP'
}
if (this.adyenConfig.pageType === 'cart') {
return ACC.config.encodedContextPath + '/expressCheckout/cart'
}
console.error('unknown page type')
return null;
}
}
})();
Loading
Loading