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

BackPort Update from Main #60

Open
wants to merge 89 commits into
base: releases/250
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
a3f1701
test commit
alakhmani Feb 13, 2024
4a8ba7a
update sample shipping calculator for Delivery Estimation
alakhmani Feb 13, 2024
04b36ce
update sample shipping calculator
alakhmani Feb 13, 2024
2af7c33
updated test for delivery estimation fields
alakhmani Feb 14, 2024
77dc051
updated comment
alakhmani Feb 15, 2024
1f8ff40
Merge pull request #50 from forcedotcom/t/commerce/obsidian/updateSam…
alakhmani Feb 15, 2024
1bcc64a
adding test for PromotionCalculatorSample class
patricia-bagzai-sf Feb 16, 2024
49827a9
Merge pull request #51 from forcedotcom/W-14847074/PromotionCalculato…
patricia-bagzai-sf Feb 16, 2024
8b1d07a
Update variable name
patricia-bagzai-sf Feb 19, 2024
a364315
Merge pull request #52 from forcedotcom/@W-14847074/UpdatePromotionCa…
patricia-bagzai-sf Feb 19, 2024
8e06355
[Tax calculator] replaced for loops with iterators
bsrilok Mar 18, 2024
ae773dc
Addressed comments
bsrilok Mar 18, 2024
9b25b3a
code changes
smahbubani99 Mar 18, 2024
0f4f9f5
update unit test
smahbubani99 Mar 18, 2024
114305e
revert comment changes
smahbubani99 Mar 18, 2024
5b7b3a9
update unit test
smahbubani99 Mar 19, 2024
baea2c2
code changes
smahbubani99 Mar 20, 2024
5f354b1
modify utests
smahbubani99 Mar 20, 2024
cc8ed61
Addressed comments
bsrilok Mar 21, 2024
244f3a0
Addressed comments
bsrilok Mar 21, 2024
9cf6c10
change method name
smahbubani99 Mar 21, 2024
6143194
update orchestrator check
smahbubani99 Mar 21, 2024
dda947b
formatting
smahbubani99 Mar 21, 2024
a7923d9
change method name again
smahbubani99 Mar 22, 2024
f036aff
Update CartCalculateSampleUnitTest.cls
smahbubani99 Mar 22, 2024
d8b7615
Merge pull request #54 from forcedotcom/addCouponsToSampleOrchestrator
smahbubani99 Mar 22, 2024
a622066
updating PromotionCalculatorSample example to evalaute BOGO promotion…
patricia-bagzai-sf Mar 26, 2024
aaf5ae4
addressing PR comments
patricia-bagzai-sf Mar 27, 2024
fc67e34
addressed comments
bsrilok Mar 28, 2024
6708c2b
Merge pull request #53 from bsrilok/t/commerce/TaxCalculator
ParameshOddepally Mar 28, 2024
46773ee
updating logic to leverage buyerActionDetails; updating tests
patricia-bagzai-sf Mar 28, 2024
2a12dbb
adding evaluate promotion logic when optionalBuyerActionDetails not p…
patricia-bagzai-sf Apr 2, 2024
6d6a57a
Merge pull request #55 from forcedotcom/W-15061789/optimizePromotoinC…
patricia-bagzai-sf Apr 2, 2024
f3fde2a
@W-15346861-refactored-cart-calculator-apex
bsrilok Apr 24, 2024
0973ccc
@W-15346861-added-test-cases
bsrilok Apr 25, 2024
2f78248
Use proper CartValidationOutputTypeEnum for PricingCalculator
pplat23 Apr 25, 2024
8d929f2
Merge pull request #56 from forcedotcom/fix-cvotype-for-pricingcalcul…
pplat23 Apr 26, 2024
cb5fe17
Fix errors in PricingServiceSample
adarshjain-sf Apr 29, 2024
2550e02
Update comments
adarshjain-sf Apr 30, 2024
95ca63f
Review comments
adarshjain-sf Apr 30, 2024
0f241eb
Update PricingServiceSample.cls
adarshjain-sf Apr 30, 2024
4ac3500
Merge pull request #58 from adarshjain-sf/patch-1
ParameshOddepally May 2, 2024
fe5d211
@W-15346861-addressed-comments
bsrilok May 12, 2024
337c8ef
@W-15346861-addressed-comments
bsrilok May 12, 2024
a84a342
@W-15346861-addressed-comments
bsrilok May 16, 2024
7edf37f
@W-15346861-addressed-comments
bsrilok May 16, 2024
fe5f02a
@W-15346861-adddressed-comments
bsrilok May 21, 2024
4c33c6f
Merge pull request #1 from bsrilok/t/commerce/W-15346861-tax-cart-cal…
bsrilok May 21, 2024
b1f924e
Merge pull request #59 from bsrilok/main
ParameshOddepally May 29, 2024
1a238d7
adding cart endpoint extension samples
balaji0034 May 30, 2024
78beff6
adding cart endpoint samples
balaji0034 May 30, 2024
b97fd25
review comments fix
balaji0034 May 31, 2024
4faa153
adding if else for currency handling
balaji0034 Jun 3, 2024
162d2d2
Update debug logs
ParameshOddepally Jun 4, 2024
4235e58
empty commit to check CLA
balaji0034 Jun 6, 2024
d0a9dab
Merge pull request #62 from balaji0034/W-15359680/cartEndpointExtensi…
balaji0034 Jun 6, 2024
56334d0
Format the file
ParameshOddepally Jun 8, 2024
da354ca
Merge pull request #63 from forcedotcom/origin/addDebugLogs
ParameshOddepally Jun 12, 2024
0ef89c5
Adding debug logs
skumar2-sfdc Jun 20, 2024
507b55c
Adding caught exception to the CartCalculateRuntimeException
skumar2-sfdc Jun 21, 2024
1a1683f
Merge pull request #65 from skumar2-sfdc/pricingCalculatorLogging
skumar2-sfdc Jun 21, 2024
61acced
Added null check for order item unit price to support bundles.
ssomanchi-salesforce Jul 12, 2024
c8a2b55
Updated the sample apex code to process the new recalculationRequeste…
cboscenco-salesforce Jul 12, 2024
5974d82
Merge pull request #66 from ssomanchi-salesforce/create-order-sample-…
gurpreetsainisalesforce Jul 13, 2024
990d4f5
Merge remote-tracking branch 'origin/main' into t/1c-cart-platform/W-…
cboscenco-salesforce Jul 16, 2024
c6d2c7a
Fixes after review.
cboscenco-salesforce Jul 16, 2024
ab490de
Merge pull request #67 from forcedotcom/t/1c-cart-platform/W-16205916…
cboscenco-salesforce Jul 16, 2024
4fdb511
Add sample and tests
l-wei791 Jul 24, 2024
5c05e87
add sample code for commerce inventory dommain, including a test to d…
sf-afoliaco Sep 26, 2024
a6fccc9
make method so can be overriable from the mock
sf-afoliaco Sep 26, 2024
83e4f91
remove fix vaules and add exception for better data validation
sf-afoliaco Sep 27, 2024
cb0fa18
add new test for calculator and comply to folder structure
sf-afoliaco Oct 2, 2024
1488d73
Fix comments
sf-afoliaco Oct 2, 2024
79dda81
address issue since warning are not supported we change the approach
sf-afoliaco Oct 3, 2024
4354939
change from warning to Error
sf-afoliaco Oct 3, 2024
a00dcbe
change method to make more sense
sf-afoliaco Oct 3, 2024
bdf15a0
Merge pull request #70 from sf-afoliaco/t/som/cc-om-not-hotdog/W-1604…
pplat23 Oct 3, 2024
53cbf10
Update test to use new constructor
l-wei791 Jan 23, 2025
73573db
Merge pull request #72 from forcedotcom/t/cc-om-not-hotdog/W-17643044
sf-afoliaco Jan 24, 2025
461dd8b
fix commit
deepalibharmal-salesforce Feb 3, 2025
a4a3ce1
Add tests
deepalibharmal-salesforce Feb 4, 2025
c5497bb
Merge pull request #73 from forcedotcom/t/1c-cart-platform/W-17689078…
deepalibharmal-salesforce Feb 5, 2025
2cc4873
sample gift card extension and test classes
alakhmani Feb 10, 2025
3fda96d
sample gift card extension class
alakhmani Feb 10, 2025
15b0ce0
review comments
alakhmani Feb 11, 2025
ea75a80
review comments
alakhmani Feb 12, 2025
c8f3a98
review comments
alakhmani Feb 12, 2025
cd816ee
review comments
alakhmani Feb 12, 2025
7625740
Merge pull request #76 from forcedotcom/t/commerce/obsidian/GiftCardE…
gurpreetsainisalesforce Feb 13, 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
11 changes: 11 additions & 0 deletions commerce/domain/checkout/giftcard/GiftCardAdapterDefault.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @description Sample GiftCard Adapter Apex that calls the default implementation.
*/
global class GiftCardAdapterDefault extends CartExtension.GiftCardAdapter {


public override void applyGiftCard(CartExtension.ApplyGiftCardRequest request){
super.applyGiftCard(request);
}

}
134 changes: 134 additions & 0 deletions commerce/domain/checkout/giftcard/GiftCardAdapterSample.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* @description Custom Gift card adapter. This class will have operations like applyGiftCard(), redeemGiftCard(), refundGiftCard().
In this sample implementation of applyGiftCard, if the https service is registered , we make a call to that third party service
with giftCardNumber and pin passed as the input in the request. The response is expected to have appliedAmount
and giftCardReference. If https service is not registered then we return a hardcoded values.

ApplyGiftCardRequest : this is the input to applyGiftCard method. request will have giftCardNumber, giftCardPin
and amount set

ApplyGiftCardResponse : This is the output type from applyGiftCard method. Response will have giftCardReference,
appliedAmount, Success or Fail status set along with errorMessage in case of Fail status.
*/

global class GiftCardAdapter extends CartExtension.GiftCardAdapter{

private static String httpHost = 'https://example.com';
private static Boolean useHTTPService = false;

public virtual override CartExtension.ApplyGiftCardResponse applyGiftCard(CartExtension.ApplyGiftCardRequest applyRequest){

Double amount = applyRequest.getAmount();
String giftCardCurrency = applyRequest.getCurrencyIsoCode();
String giftCardCode = applyRequest.getGiftCardCode();
String pin = applyRequest.getPin();

CartExtension.ApplyGiftCardResponse response = null;

if(useHTTPService) {
response = applyGiftCardService(giftCardCode, pin, amount, giftCardCurrency);
} else {
response = applyGiftCardMockedService(giftCardCode, pin, amount, giftCardCurrency);
}

return response;

}

private CartExtension.ApplyGiftCardResponse applyGiftCardMockedService(String giftCardCode, String giftCardPin,
Double amount, String giftCardCurrency) {
CartExtension.ApplyGiftCardResponse applyResponse = new CartExtension.ApplyGiftCardResponse();

applyResponse.setGiftCardReference('123456789');
applyResponse.setAppliedAmount(50);
applyResponse.setLastFour('6789');
applyResponse.setStatus('Success');

return applyResponse;


}

private CartExtension.ApplyGiftCardResponse applyGiftCardService(String giftCardCode, String giftCardPin, Double amount) {

final Integer successfulHttpRequest = 200;
CartExtension.ApplyGiftCardResponse applyResponse;

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(httpHost + '/apply-gift-card');
request.setMethod('POST');
HttpResponse response = http.send(request);


if (response.getStatusCode() == successfulHttpRequest) {
// Parse JSON response
String responseBody = response.getBody();
applyResponse = processSuccessResponseFromService(responseBody, amount);

}else{
// Read the error details
String responseBody = response.getBody();
applyResponse = processFailedResponseFromService(response);

}
return applyResponse;

}

private CartExtension.ApplyGiftCardResponse processSuccessResponseFromService(String thirdPartyResponse, Double amount) {
CartExtension.ApplyGiftCardResponse applyResponse = new CartExtension.ApplyGiftCardResponse();

// Parse JSON using JSON.deserialize or JSON.deserializeUntyped
Map<String, Object> resultMap = (Map<String, Object>) JSON.deserializeUntyped(thirdPartyResponse);

String giftCardReference = (String)resultMap.get('giftCardReference');

Double availableAmount = (Double)resultMap.get('availableAmount');
if(availableAmount >= amount){
applyResponse.setAppliedAmount(amount);
} else if(availableAmount < amount && availableAmount>0){
applyResponse.setAppliedAmount(availableAmount);
} else if(availableAmount == 0){
applyResponse.setAppliedAmount(0);
applyResponse.setErrorMessage('Zero balance in gift card');
applyResponse.setStatus('Fail');
applyResponse.setGiftCardReference(giftCardReference);
applyResponse.setLastFour(giftCardReference.substring(giftCardReference.length() - 4));
return applyResponse;

}
applyResponse.setGiftCardReference(giftCardReference);
applyResponse.setLastFour(giftCardReference.substring(giftCardReference.length() - 4));
applyResponse.setStatus('Success');

return applyResponse;
}

private CartExtension.ApplyGiftCardResponse processFailedResponseFromService(HttpResponse response) {

CartExtension.ApplyGiftCardResponse applyResponse = new CartExtension.ApplyGiftCardResponse();

// Read the error details
String responseBody = response.getBody();

System.debug('Error Status Code: ' + response.getStatusCode());
System.debug('Error Body: ' + responseBody);

// Optional: Parse error if response is JSON
if (response.getHeader('Content-Type').contains('application/json')) {
Map<String, Object> errorMap = (Map<String, Object>) JSON.deserializeUntyped(responseBody);

String errorMessage = (String) errorMap.get('message');
System.debug('Error Message: ' + errorMessage);
applyResponse.setStatus('Fail');
applyResponse.setErrorMessage(errorMessage);
}
return applyResponse;
}

public void shouldUseHttpService(Boolean input){
useHTTPService = input;
}

}
17 changes: 17 additions & 0 deletions commerce/domain/checkout/giftcard/GiftCardMockHttpResponseFail.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@isTest
global class GiftCardMockHttpResponseFail implements HttpCalloutMock {
// Implement this interface method
global HTTPResponse respond(HTTPRequest req) {
// Optionally, only send a mock response for a specific endpoint
// and method.
System.assertEquals('https://example.com/apply-gift-card', req.getEndpoint());
System.assertEquals('POST', req.getMethod());

// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type', 'application/json');
res.setBody('{"error": "Internal Server Error", "message": "Something went wrong"}');
res.setStatusCode(500);
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@isTest
global class GiftCardMockHttpResponseSuccess implements HttpCalloutMock {
// Implement this interface method
global HTTPResponse respond(HTTPRequest req) {
// Optionally, only send a mock response for a specific endpoint
// and method.
System.assertEquals('https://example.com/apply-gift-card', req.getEndpoint());
System.assertEquals('POST', req.getMethod());

// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type', 'application/json');
res.setBody('{"giftCardReference":"111111111","availableAmount":20}');
res.setStatusCode(200);
return res;
}
}
81 changes: 81 additions & 0 deletions commerce/domain/checkout/giftcard/GiftcardAdapterUnitTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@IsTest
global class GiftcardAdapterUnitTest{

/**
* @description Verify that SplitShipmentService invoked the default implementation.
*/
@IsTest
public static void applyGiftCard(){
CartExtension.ApplyGiftCardRequest applyRequest = new CartExtension.ApplyGiftCardRequest('123456789', '1234', 50,'USD');
GiftCardAdapterSample adapter = new GiftCardAdapterSample();

// Act
Test.startTest();
CartExtension.ApplyGiftCardResponse applyResponse = adapter.applyGiftCard(applyRequest);
Test.stopTest();


// Assert
System.assertEquals(applyResponse.getGiftCardReference, '123456789')
System.assertEquals(applyResponse.getStatus(), 'Success');
System.assertEquals(applyResponse.getAppliedAmount(), 50);
System.assertEquals(applyResponse.getErrorMessage(), null);
}

@IsTest
public static void applyGiftCardWithThirdPartyServiceSuccess(){
CartExtension.ApplyGiftCardRequest applyRequest = new CartExtension.ApplyGiftCardRequest('111111111', '1234', 50,'USD');
GiftCardAdapter adapter = new GiftCardAdapter();

adapter.shouldUseHttpService(true);

// Set mock callout class
System.Test.setMock(HttpCalloutMock.class, new GiftCardMockHttpResponseSuccess());
// Act
Test.startTest();
CartExtension.ApplyGiftCardResponse applyResponse = adapter.applyGiftCard(applyRequest);
Test.stopTest();

System.assertEquals(applyResponse.getGiftCardReference(), '111111111');
System.assertEquals(applyResponse.getStatus(), 'Success');
System.assertEquals(applyResponse.getAppliedAmount(), 20);
System.assertEquals(applyResponse.getLastFour(), '1111');


}

@IsTest
public static void applyGiftCardWithThirdPartyServiceFail(){
CartExtension.ApplyGiftCardRequest applyRequest = new CartExtension.ApplyGiftCardRequest('111111111', '1234', 50,'USD');
GiftCardAdapter adapter = new GiftCardAdapter();

adapter.shouldUseHttpService(true);

// Set mock callout class
System.Test.setMock(HttpCalloutMock.class, new GiftCardMockHttpResponseFail());
// Act
Test.startTest();
CartExtension.ApplyGiftCardResponse applyResponse = adapter.applyGiftCard(applyRequest);
Test.stopTest();

System.assertEquals(applyResponse.getStatus(), 'Fail');
}

@IsTest
public static void applyGiftCardWithDefaultImplementation(){
CartExtension.ApplyGiftCardRequest applyRequest = new CartExtension.ApplyGiftCardRequest('987654321', '1234', 50,'USD');
GiftCardAdapterDefault defaultAdapter = new GiftCardAdapterDefault();
try{
// Act
Test.startTest();
defaultAdapter.applyGiftCard(applyRequest);
Test.stopTest();

// If an exception was not thrown, fail the test
System.assert(false, 'Expected exception was not thrown');
}catch(CalloutException e){
// Assert that the exception was thrown
System.assert(e.getMessage().contains('Native gift card is not supported'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public virtual class CreateOrderSample extends CartExtension.CheckoutCreateOrder
List<OrderItem> orderItems = orderGraph.getOrderItems();
Decimal roundedPrice = 0.0;
for (OrderItem orderItem : orderItems) {
roundedPrice += orderItem.UnitPrice.round(System.RoundingMode.CEILING);
if(orderItem.UnitPrice != null) {
roundedPrice += orderItem.UnitPrice.round(System.RoundingMode.CEILING);
}
}
order.Description += roundedPrice;
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @description
*
* USE CASE
*
* The customer was notified by the warehouse that during the inventory process, SKU_RED_SHIRT was accidentally made available.
* Due to a system issue, the warehouse is currently unable to mark it as unavailable again.
* Customer does NOT want to sell the SKU_RED_SHIRT in the store front
*
* SI Solution
* Extended inventory calculator to show a message during checkout that SKU_RED_SHIRT that shipping migth be delay
*
*/
public class InventoryCartCalculatorSample extends CartExtension.InventoryCartCalculator {


private static final String SKU_RED_SHIRT = 'SKU_RED_SHIRT';
private static final String SKU_RED_SHIRT_MESSAGE = 'Apologies for the inconvenience, but there is an issue with SKU_RED_SHIRT, and it is currently unavailable.';

public InventoryCartCalculatorSample() {
super();
}

/**
* @description Constructor used by unit tests only.
* @param apexExecutor Executor which executes various calculators. Can be used to stub calculation results or delegate calculations to actual Calculator. See <<CartCalculateExecutorMock>>.
*/
public InventoryCartCalculatorSample(CartExtension.CartCalculateExecutorMock apexExecutor) {
// Must call super constructor in order for provided Executor to be used for calculations
super(apexExecutor);
}

public virtual override void calculate(CartExtension.CartCalculateCalculatorRequest request) {

CartExtension.Cart cart = request.getCart();

super.calculate(request);

CartExtension.CartItemList cartItemCollection = cart.getCartItems();
Iterator<CartExtension.CartItem> cartItemCollectionIterator = cartItemCollection.iterator();

while (cartItemCollectionIterator.hasNext()) {
CartExtension.CartItem cartItem = cartItemCollectionIterator.next();

system.debug('CART ITEM SKU: ' + cartItem.getSku());
if (cartItem.getSku().equals(SKU_RED_SHIRT)) {
CartExtension.CartValidationOutput cvo = new CartExtension.CartValidationOutput(
CartExtension.CartValidationOutputTypeEnum.INVENTORY,
CartExtension.CartValidationOutputLevelEnum.ERROR, cartItem);
cvo.setMessage(SKU_RED_SHIRT_MESSAGE);
cart.getCartValidationOutputs().add(cvo);
system.debug('CART CVO: ' + cvo);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading