lib/app_manager/model.rb in app_manager-2.3.2 vs lib/app_manager/model.rb in app_manager-2.3.3
- old
+ new
@@ -344,9 +344,30 @@
else
return nil
end
end
+ def usage_charge_call(amount, description = '', shopify_charge_id = nil)
+ gq_obj = AppManager::GraphqlHelper.new(shopify_domain, shopify_token)
+
+ # Validate amount is present and is a valid number
+ return 'Amount must be present and a positive float' if amount.blank? || !amount.is_a?(Numeric) || amount.to_f <= 0
+
+ # Use the provided shopify_charge_id if available, else use active_shopify_charge_id
+ charge_id = shopify_charge_id.presence || active_shopify_charge_id
+
+ # Return nil if there's no valid charge_id
+ return nil if charge_id.blank?
+
+ # Ensure amount is a float
+ amount = amount.to_f
+
+ # Make the usage charge API call
+ gq_obj.usage_charge_api_call(charge_id, amount, description)
+ end
+
+
+
def config_trial_days
@field_names = AppManager.configuration.field_names
if !@field_names.nil? && @field_names.has_key?('total_trial_days') && !@field_names['total_trial_days'].nil? && !@field_names['total_trial_days'].blank?
return @field_names['total_trial_days']
else