Skip to content

Commit

Permalink
[Coupon] Data Mapper UI (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadaismail-stripe authored Nov 15, 2022
1 parent c9a44cf commit c44670a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 18 deletions.
6 changes: 2 additions & 4 deletions lib/stripe-force/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Constants

CPQ_QUOTE = 'SBQQ__Quote__c'
CPQ_QUOTE_LINE = 'SBQQ__QuoteLine__c'
CPQ_QUOTE_LINE_PRODUCT = 'SBQQ__Product__c'
CPQ_QUOTE_LINE_PRICEBOOK_ENTRY = 'SBQQ__PricebookEntryId__c'
CPQ_CONSUMPTION_SCHEDULE = 'SBQQ__OrderItemConsumptionSchedule__c'
CPQ_CONSUMPTION_RATE = 'SBQQ__OrderItemConsumptionRate__c'

Expand Down Expand Up @@ -86,10 +88,6 @@ class CPQProductBillingTypeOptions < T::Enum
end
end

CPQ_QUOTE_LINE = 'SBQQ__QuoteLine__c'
CPQ_QUOTE_LINE_PRODUCT = 'SBQQ__Product__c'
CPQ_QUOTE_LINE_PRICEBOOK_ENTRY = 'SBQQ__PricebookEntryId__c'

# custom fields added by our package
GENERIC_STRIPE_ID = 'Stripe_ID__c'
ORDER_LINE_SKIP = 'Skip_Line_Item__c'
Expand Down
3 changes: 0 additions & 3 deletions lib/stripe-force/db/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def required_mappings
"product" => {},
"customer" => {},
"invoice" => {},

"subscription_schedule" => {
"start_date" => "#{CPQ_QUOTE}.#{CPQ_QUOTE_SUBSCRIPTION_START_DATE}",
"iterations" => "#{CPQ_QUOTE}.#{CPQ_QUOTE_SUBSCRIPTION_TERM}",
Expand All @@ -171,14 +170,12 @@ def default_mappings
"name" => "Name",
"phone" => "Phone",
"description" => "Description",

# TODO may need to split BillingStreet into `line2` if multiple lines
"address.line1" => "BillingStreet",
"address.city" => "BillingCity",
"address.state" => "BillingState",
"address.postal_code" => "BillingPostalCode",
"address.country" => "BillingCountry",

"shipping.name" => "Name",
"shipping.phone" => "Phone",
"shipping.address.line1" => "ShippingStreet",
Expand Down
6 changes: 4 additions & 2 deletions sfdx/force-app/main/default/classes/setupAssistant.cls
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ public with sharing class setupAssistant {
'Order' => utilities.getListOfFieldsByObject('Order'),
'Account' => utilities.getListOfFieldsByObject('Account'),
'Product2' => utilities.getListOfFieldsByObject('Product2'),
'PricebookEntry' => utilities.getListOfFieldsByObject('PricebookEntry')
'PricebookEntry' => utilities.getListOfFieldsByObject('PricebookEntry'),
'Stripe_Coupon_Beta__c' => utilities.getListOfFieldsByObject('Stripe_Coupon_Beta__c')
};
rd.put('fieldListByObjectMap', fieldListByObjectMap);
} else {
Expand Down Expand Up @@ -231,7 +232,7 @@ public with sharing class setupAssistant {
rd.put('formattedStripeSubscriptionItemFields', (List<Object>)responseBody.get('formattedStripeSubscriptionItemFields'));
rd.put('formattedStripePriceFields', (List<Object>)responseBody.get('formattedStripePriceFields'));
rd.put('formattedStripePriceOrderItemFields', (List<Object>)responseBody.get('formattedStripePriceFields'));

rd.put('formattedStripeCouponFields', (List<Object>)responseBody.get('formattedStripeCouponFields'));
} else {
errorLogger.create('getFormattedStripeObjectFields', String.valueOf(response.getStatusCode()), (String)response.getStatus(), 'Failed to get mapping configuration from ruby service.');
}
Expand Down Expand Up @@ -698,6 +699,7 @@ public with sharing class setupAssistant {
'Order',
'OrderItem',
'PricebookEntry'
// 'Stripe_Coupon_Beta__c'
};

if ((Boolean)utilities.isCpqEnabled()) {
Expand Down
5 changes: 3 additions & 2 deletions sfdx/force-app/main/default/classes/utilities.cls
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public with sharing class utilities {
'Pricebook2',
'ContractLineItem',
'OpportunityLineItem',
'ProductItem'
'ProductItem',
'Stripe_Coupon_Beta__c'
};
if(listOfImportantObjectsApiNames.contains(stringReferncedObjecect)) {
objectFieldMap = addFieldsToObjectFieldMap(objectFieldMap, objectApiFieldMap, objectFieldName, isFieldCustom, typeOfField, isObjectCustom);
Expand Down Expand Up @@ -158,7 +159,7 @@ public with sharing class utilities {
}

private static Map<String, Object> addFieldsToObjectFieldMap(Map<String, Object> objectFieldMap, Map<String, Schema.SObjectField> objectApiFieldMap, String objectFieldName, Boolean isFieldCustom, String typeOfField, Boolean isObjectCustom) {
objectFieldMap.put('label',objectApiFieldMap.get(objectFieldName).getDescribe().getLabel());
objectFieldMap.put('label', objectApiFieldMap.get(objectFieldName).getDescribe().getLabel());
//REST API is case sensitive and requires CamelCase field names
objectFieldMap.put('value',objectApiFieldMap.get(objectFieldName).getDescribe().getName());
objectFieldMap.put('type',typeOfField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<lightning-vertical-navigation-item label="Product" name="product"></lightning-vertical-navigation-item>
<lightning-vertical-navigation-item label="Price" name="price"></lightning-vertical-navigation-item>
<lightning-vertical-navigation-item label="Price Order Line" name="priceOrderItem"></lightning-vertical-navigation-item>
<lightning-vertical-navigation-item label="Coupon" name="coupon"></lightning-vertical-navigation-item>
</lightning-vertical-navigation-section>
</lightning-vertical-navigation>
</div>
Expand Down
35 changes: 29 additions & 6 deletions sfdx/force-app/main/default/lwc/dataMappingStep/dataMappingStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export default class DataMappingStep extends LightningElement {
objectName: "PricebookEntry",
friendlyName: 'Price Order Item',
description: 'Price order items define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of a single product.'
},
"coupon": {
objectName: "Stripe_Coupon_Beta__c",
friendlyName: 'Stripe Coupon',
description: 'Coupons contain information about a percent-off or amount-off discount you might want to apply to a subscription or subscription item.'
}
}
@track sfFieldOptions = [];
Expand All @@ -67,6 +72,7 @@ export default class DataMappingStep extends LightningElement {
@track subscriptionItemMappings;
@track priceMappings;
@track priceOrderItemMappings;
@track couponMappings;
@track fieldListByObjectMap;
// allMappingConfigurations holds all mappings retrieved from ruby, value is set in `getMappingConfigurations`
@track allMappingConfigurations;
Expand All @@ -83,7 +89,8 @@ export default class DataMappingStep extends LightningElement {
subscription_phase: {},
subscription_item: {},
price: {},
price_order_item: {}
price_order_item: {},
coupon: {}
},
// these are user defined mappings from Salesforce fields to Stripe fields
field_mappings: {
Expand All @@ -93,17 +100,19 @@ export default class DataMappingStep extends LightningElement {
subscription_phase: {},
subscription_item: {},
price: {},
price_order_item: {}
price_order_item: {},
coupon: {}
},
// these are default mappings sent from Ruby (can be overeidden in mapp)
// these are default mappings sent from Ruby (can be overridden in map)
default_mappings: {
customer: {},
product: {},
subscription_schedule: {},
subscription_phase: {},
subscription_item: {},
price: {},
price_order_item: {}
price_order_item: {},
coupon: {}
},
// these are required mappings sent from Ruby
required_mappings: {
Expand All @@ -113,7 +122,8 @@ export default class DataMappingStep extends LightningElement {
subscription_phase: {},
subscription_item: {},
price: {},
price_order_item: {}
price_order_item: {},
coupon: {}
}
};
@track customerMetadataFields = {metadataMapping: {
Expand Down Expand Up @@ -165,6 +175,13 @@ export default class DataMappingStep extends LightningElement {
description: '',
fields: []
}};
@track couponMetadataFields = {metadataMapping: {
label: '',
name: '',
value: '',
description: '',
fields: []
}};

@track activeStripeObjectMappings = this.customerMappings;
@track activeStripeObjectMetadataFields = this.customerMetadataFields;
Expand Down Expand Up @@ -230,6 +247,11 @@ export default class DataMappingStep extends LightningElement {
object: 'price_order_item',
mappingsObject: this.priceOrderItemMappings,
metadataMappingsObject: this.priceOrderItemMetadataFields
},
{
object: 'coupon',
mappingsObject: this.couponMappings,
metadataMappingsObject: this.couponMetadataFields
}
];
}
Expand Down Expand Up @@ -616,7 +638,8 @@ export default class DataMappingStep extends LightningElement {
this.subscriptionItemMappings = responseData.results.formattedStripeSubscriptionItemFields;
this.priceMappings = responseData.results.formattedStripePriceFields;
this.priceOrderItemMappings = responseData.results.formattedStripePriceOrderItemFields;

this.couponMappings = responseData.results.formattedStripeCouponFields;

this.getPicklistValuesForMapper(true, '', false);
} catch (error) {
const errorMessage = getErrorMessage(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
<allowDelete>true</allowDelete>
<allowEdit>true</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>true</modifyAllRecords>
<object>Stripe_Coupon_Beta__c</object>
<viewAllRecords>true</viewAllRecords>
</objectPermissions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@
<allowDelete>true</allowDelete>
<allowEdit>true</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>true</modifyAllRecords>
<object>Stripe_Coupon_Beta__c</object>
<viewAllRecords>false</viewAllRecords>
<viewAllRecords>true</viewAllRecords>
</objectPermissions>
<objectPermissions>
<allowCreate>true</allowCreate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
<allowDelete>true</allowDelete>
<allowEdit>true</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>true</modifyAllRecords>
<object>Stripe_Coupon_Beta__c</object>
<viewAllRecords>true</viewAllRecords>
</objectPermissions>
Expand Down
8 changes: 8 additions & 0 deletions test/integration/translate/test_coupon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class Critic::CouponTranslation < Critic::FunctionalTest
end

it 'translate an SF coupon with percent off set' do
@user.field_defaults = {
"coupon" => {
"metadata.customMetadataKey" => "customMetadataValue",
},
}
@user.save

# setup
COUPON_NAME = '100% off coupon'
COUPON_PERCENT_OFF = 100
Expand Down Expand Up @@ -36,6 +43,7 @@ class Critic::CouponTranslation < Critic::FunctionalTest
assert_equal(COUPON_PERCENT_OFF, stripe_coupon.percent_off)
assert_equal('once', stripe_coupon.duration)
assert_nil(stripe_coupon.currency)
assert_equal('customMetadataValue', stripe_coupon.metadata['customMetadataKey'])
assert_equal(sf_coupon.Id, stripe_coupon.metadata['salesforce_stripe_coupon_beta_id'])
assert_match(sf_coupon.Id, stripe_coupon.metadata['salesforce_stripe_coupon_beta_link'])
end
Expand Down

0 comments on commit c44670a

Please sign in to comment.