Skip to content

Commit

Permalink
[Coupons] Add Order Item Association custom object and updateCoupon t…
Browse files Browse the repository at this point in the history
…rigger (#888)
  • Loading branch information
nadaismail-stripe authored Nov 15, 2022
1 parent c05c36e commit 691672e
Show file tree
Hide file tree
Showing 20 changed files with 759 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/stripe-force/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module Constants
SF_CONSUMPTION_RATE = 'ConsumptionRate'
SF_CONTRACT = 'Contract'
SF_STRIPE_COUPON = 'Stripe_Coupon_Beta__c'
SF_STRIPE_COUPON_SERIALIZED = 'Stripe_Coupon_Beta_Serialized__c'
SF_STRIPE_COUPON_QUOTE_LINE_ASSOCIATION = 'Stripe_Coupon_Beta_Quote_Line_Associatio__c'
SF_STRIPE_COUPON_ORDER_ITEM_ASSOCIATION = 'Stripe_Coupon_Beta_Order_Item_Associatio__c'

SF_ID = 'Id'
SF_LAST_MODIFIED_DATE = 'LastModifiedDate'
Expand Down
20 changes: 20 additions & 0 deletions lib/stripe-force/translate/coupon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ def translate_coupon(sf_coupon)

coupon
end

def self.get_salesforce_stripe_coupons_associated_to_order_line(sf_client:, sf_order_line_id:)
order_item_associations = sf_client.query("Select Id from #{SF_STRIPE_COUPON_ORDER_ITEM_ASSOCIATION} where Order_Item__c = '#{sf_order_line_id}'")

if !order_item_associations || order_item_associations.size == 0
log.info "no stripe coupon order line associations related to this order line", salesforce_object: sf_order_line_id
return
end

# there could be multiple coupons associated with a single order line
coupons = order_item_associations.map do |order_item_association|
association = sf_client.find(SF_STRIPE_COUPON_ORDER_ITEM_ASSOCIATION, order_item_association.Id)
coupon = sf_client.query("Select Id from #{SF_STRIPE_COUPON_SERIALIZED} where Id = '#{association.Stripe_Coupon__c}'")

# return the coupon object
sf_client.find(SF_STRIPE_COUPON_SERIALIZED, coupon.first.Id)
end

coupons
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<actionOverrides>
<actionName>Accept</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Accept</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Accept</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<allowInChatterGroups>false</allowInChatterGroups>
<compactLayoutAssignment>SYSTEM</compactLayoutAssignment>
<deploymentStatus>Deployed</deploymentStatus>
<description>Custom junction object linking a Stripe Coupon and an Order Line.</description>
<enableActivities>false</enableActivities>
<enableBulkApi>true</enableBulkApi>
<enableFeeds>false</enableFeeds>
<enableHistory>false</enableHistory>
<enableLicensing>false</enableLicensing>
<enableReports>false</enableReports>
<enableSearch>false</enableSearch>
<enableSharing>true</enableSharing>
<enableStreamingApi>true</enableStreamingApi>
<externalSharingModel>ControlledByParent</externalSharingModel>
<label>Stripe Coupon Beta Order Item Associatio</label>
<nameField>
<displayFormat>{0000}</displayFormat>
<label>Stripe Coupon Beta Order Item Associatio Name</label>Quot
<type>AutoNumber</type>
</nameField>
<pluralLabel>Stripe Coupon Beta Order Items</pluralLabel>
<searchLayouts></searchLayouts>
<sharingModel>ControlledByParent</sharingModel>
<validationRules>
<fullName>Order_Item_Field_Must_Be_Set</fullName>
<description>Order_Item__c is a required field.</description>
<active>true</active>
<errorConditionFormula>ISBLANK(Order_Item__c)</errorConditionFormula>
<errorMessage>Order_Item__c is a required field.</errorMessage>
</validationRules>
<visibility>Public</visibility>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Order_Item__c</fullName>
<externalId>false</externalId>
<label>Order Item</label>
<referenceTo>OrderItem</referenceTo>
<relationshipLabel>Stripe Coupon Beta Order Item Connection</relationshipLabel>
<relationshipName>Stripe_Coupon_Beta_Order_Item_Connection</relationshipName>
<reparentableMasterDetail>false</reparentableMasterDetail>
<trackTrending>false</trackTrending>
<type>Lookup</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Stripe_Coupon__c</fullName>
<externalId>false</externalId>
<label>Stripe Coupon</label>
<referenceTo>Stripe_Coupon_Beta_Serialized__c</referenceTo>
<relationshipLabel>Stripe Coupon Beta Order Item Link</relationshipLabel>
<relationshipName>Stripe_Coupon_Beta_Order_Item_Link</relationshipName>
<relationshipOrder>0</relationshipOrder>
<reparentableMasterDetail>false</reparentableMasterDetail>
<trackTrending>false</trackTrending>
<type>MasterDetail</type>
<writeRequiresMasterRead>true</writeRequiresMasterRead>
</CustomField>
Loading

0 comments on commit 691672e

Please sign in to comment.