-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from jbachelet/fix/issue-134
Fixing issue-134 and revamping how Core is getting customer promotions to actually get the promotions from when the customer is authenticated and not as a guest customer
- Loading branch information
Showing
18 changed files
with
756 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfile.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @author Jordane Bachelet | ||
* @date January 3rd, 2022 | ||
* | ||
* @description This class is used to retrieve a customer profile from the OCAPI Shop API from B2C Commerce. | ||
* The goal of using the Shop API is to retrieve custom data based on customer's context | ||
*/ | ||
public with sharing class B2CIACustomerShopperProfile { | ||
/** | ||
* @description This class is used to process the collection of inputs used to retrieve a | ||
* customer profile from B2C Commerce. When successful, it returns customer profile data. | ||
* | ||
* @param customerShopperProfileInputList {List<B2CIACustomerShopperProfileInput>} Represents the collection of input | ||
* properties used to request an access token | ||
* @return {List<B2CIACustomerShopperProfileResult>} Returns a result representing the access token | ||
* request response (containing a token or the error | ||
*/ | ||
@InvocableMethod( | ||
Label='B2C: Get Customer Shopper Profile' | ||
Description='Retrieve the Shopper Customer Profile from B2C Commerce to get data from the current customer\'s context' | ||
) | ||
public static List<B2CIACustomerShopperProfileResult> getCustomerShopperProfile( | ||
List<B2CIACustomerShopperProfileInput> customerShopperProfileInputList | ||
) { | ||
List<B2CIACustomerShopperProfileResult> outputObj = new List<B2CIACustomerShopperProfileResult>(); | ||
|
||
for (B2CIACustomerShopperProfileInput b2creq : customerShopperProfileInputList) { | ||
HttpRequest req = B2CHttpRequestHelper.getShopCustomerProfileRequest( | ||
b2creq.domain, b2creq.siteId, b2creq.version, b2creq.customerId, b2creq.clientId, b2creq.token, b2creq.expandParameter | ||
); | ||
|
||
Http https = new Http(); | ||
HttpResponse res = https.send(req); | ||
B2CIACustomerShopperProfileResult result = new B2CIACustomerShopperProfileResult(); | ||
|
||
result.status = res.getStatus(); | ||
result.statusCode = res.getStatusCode(); | ||
result.responseBody = res.getBody(); | ||
result.isError = false; | ||
|
||
if (result.statusCode == 200) { | ||
JSONParse responseParsedJSON = new JSONParse(res.getBody()); | ||
result.promotionIds = new List<String>(); | ||
try { | ||
List<JSONParse> promotionsList = responseParsedJSON.get('c_active_promotions').asList(); | ||
for (JsonParse promotionItem : promotionsList) { | ||
result.promotionIds.add(promotionItem.getStringValue()); | ||
} | ||
} catch (Exception e) { | ||
// No coupons found in the promotion | ||
System.debug('No promotions found for the profile.'); | ||
} | ||
result.totalPromotionsSize = result.promotionIds.size(); | ||
} else { | ||
result.errorMessage = B2CConstant.ERRORS_B2CCOMMERCE_SHOP_CUSTOMER_RETRIEVAL; | ||
result.isError = true; | ||
} | ||
|
||
outputObj.add(result); | ||
} | ||
|
||
return outputObj; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfile.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
27 changes: 27 additions & 0 deletions
27
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfileInput.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author Jordane Bachelet | ||
* @date January 3rd, 2022 | ||
* @description This is the input class for customer shopper profile retrieval. | ||
*/ | ||
public with sharing class B2CIACustomerShopperProfileInput { | ||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String siteId; | ||
|
||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String customerId; | ||
|
||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String clientId; | ||
|
||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String token; | ||
|
||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String domain; | ||
|
||
@AuraEnabled @InvocableVariable(Required=true) | ||
public String version; | ||
|
||
@AuraEnabled @InvocableVariable(Required=false) | ||
public String expandParameter; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfileInput.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
39 changes: 39 additions & 0 deletions
39
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfileResult.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @author Jordane Bachelet | ||
* @date January 3rd, 2022 | ||
* | ||
* @description This is the wrapper used by the B2CIACustomerShopperProfile class to capture the B2C Commerce API result | ||
*/ | ||
public class B2CIACustomerShopperProfileResult { | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// Include the REST response properties | ||
//////////////////////////////////////////////////////////////// | ||
@InvocableVariable | ||
public String status; | ||
|
||
@InvocableVariable | ||
public Integer statusCode; | ||
|
||
@InvocableVariable | ||
public String responseBody; | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// Include any error messaging or detail flags | ||
//////////////////////////////////////////////////////////////// | ||
@InvocableVariable | ||
public Boolean isError; | ||
|
||
@InvocableVariable | ||
public String errorMessage; | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// Include the deserialized properties from the response | ||
//////////////////////////////////////////////////////////////// | ||
|
||
@InvocableVariable | ||
public Integer totalPromotionsSize; | ||
|
||
@InvocableVariable | ||
public List<String> promotionIds; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfileResult.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
69 changes: 69 additions & 0 deletions
69
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfile_Test.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* @author Jordane Bachelet | ||
* @date Dec 28, 2021 | ||
* | ||
* @description This class exercises the successful and failed process of customer shopper details retrieval. | ||
*/ | ||
@IsTest | ||
private class B2CIACustomerShopperProfile_Test { | ||
@IsTest | ||
static void testIsSuccess() { | ||
Test.startTest(); | ||
Test.setMock(HttpCalloutMock.class, new B2CHttpTestCalloutMockGenerator('CustomerShopDetailsSuccessWithPromotions')); | ||
|
||
// Seed the input arguments | ||
B2CIACustomerShopperProfileInput req = new B2CIACustomerShopperProfileInput(); | ||
req.siteId = 'siteId'; | ||
req.customerId = 'customerId'; | ||
req.clientId = 'clientId'; | ||
req.token = 'token'; | ||
req.domain = 'domain'; | ||
req.version = 'version'; | ||
req.expandParameter = 'parameter'; | ||
|
||
// Request the authToken and validate the results | ||
List<B2CIACustomerShopperProfileResult> resultList = B2CIACustomerShopperProfile.getCustomerShopperProfile( | ||
new List<B2CIACustomerShopperProfileInput>{ | ||
req | ||
} | ||
); | ||
Test.stopTest(); | ||
|
||
// Validate that the request processed successfully | ||
System.assertEquals(resultList.size() > 0, true, 'Expected a result to be processed and returned in the results'); | ||
System.assertEquals(resultList[0].statusCode, 200, 'Expected a successful http statusCode to be returned as part of this request'); | ||
System.assertEquals(resultList[0].isError, false, 'Expected the isError flag to be false.'); | ||
System.assertEquals(resultList[0].totalPromotionsSize, 2, 'Expected two promotions to be returned from the mock response'); | ||
System.assertEquals(resultList[0].promotionIds.size(), 2, 'Expected two promotions to be returned from the mock response'); | ||
} | ||
|
||
@IsTest | ||
static void testIsFailure() { | ||
Test.startTest(); | ||
Test.setMock(HttpCalloutMock.class, new B2CHttpTestCalloutMockGenerator('CustomerShopDetailsFailure')); | ||
|
||
// Seed the input arguments | ||
B2CIACustomerShopperProfileInput req = new B2CIACustomerShopperProfileInput(); | ||
req.siteId = 'siteId'; | ||
req.customerId = 'customerId'; | ||
req.clientId = 'clientId'; | ||
req.token = 'token'; | ||
req.domain = 'domain'; | ||
req.version = 'version'; | ||
req.expandParameter = 'parameter'; | ||
|
||
// Request the authToken and validate the results | ||
List<B2CIACustomerShopperProfileResult> resultList = B2CIACustomerShopperProfile.getCustomerShopperProfile( | ||
new List<B2CIACustomerShopperProfileInput>{ | ||
req | ||
} | ||
); | ||
|
||
Test.stopTest(); | ||
|
||
// Validate that the request processed with a failure | ||
System.assertEquals(resultList.size() > 0, true, 'Expected a result to be processed and returned in the results'); | ||
System.assertEquals(resultList[0].statusCode, 400, 'Expected a failed (400) http statusCode to be returned as part of this request'); | ||
System.assertEquals(resultList[0].isError, true, 'Expected the isError flag to be true.'); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/sfdc/base/main/default/classes/B2CIACustomerShopperProfile_Test.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.