-
Notifications
You must be signed in to change notification settings - Fork 2
/
commerce_license_billing.rules_defaults.inc
242 lines (235 loc) · 9.34 KB
/
commerce_license_billing.rules_defaults.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* @file
* Default rule configurations for Commerce License Billing.
*/
/**
* Implements hook_default_rules_configuration_alter().
*/
function commerce_license_billing_default_rules_configuration_alter(&$configs) {
// The order account rules run at commerce_checkout_complete, which is usually
// after commerce_payment_order_paid_in_full. This means that if the checkout
// was anonymous, a recurring order can't be opened because the order owner
// is not yet known. Until this is fixed in Commerce, this module needs to
// ensure that these rules run at commerce_payment_order_paid_in_full as well.
$configuration_names = array(
'commerce_checkout_order_convert',
'commerce_checkout_new_account',
);
foreach ($configuration_names as $configuration_name) {
if (isset($configs[$configuration_name])) {
$configs[$configuration_name]->event('commerce_payment_order_paid_in_full');
}
}
}
/**
* Implements hook_default_rules_configuration().
*/
function commerce_license_billing_default_rules_configuration() {
$items = array();
if (!field_info_field('cl_billing_type') || !field_info_field('cl_billing_cycle_type')) {
// We can't run this until fields are installed. Fail gracefully in the
// meantime. Seems to only crop during installation as part of an install
// profile.
return $items;
}
$items['commerce_license_billing_set_postpaid_product_price'] = entity_import('rules_config', '{ "commerce_license_billing_set_postpaid_product_price" : {
"LABEL" : "Set the price of postpaid products to 0",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-5",
"OWNER" : "rules",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [
"rules",
"commerce_license_billing",
"commerce_line_item",
"commerce_product_reference"
],
"ON" : { "commerce_product_calculate_sell_price" : [] },
"IF" : [
{ "NOT entity_is_of_bundle" : {
"entity" : [ "commerce-line-item" ],
"type" : "commerce_line_item",
"bundle" : { "value" : { "recurring" : "recurring" } }
}
},
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "cl_billing_type"
}
},
{ "commerce_license_billing_product_elligible" : { "commerce_product" : [ "commerce-line-item:commerce-product" ] } },
{ "data_is" : {
"data" : [ "commerce-line-item:commerce-product:cl-billing-type" ],
"value" : "postpaid"
}
}
],
"DO" : [
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : "0",
"component_name" : "base_price",
"round_mode" : "0"
}
}
]
}
}');
$items['commerce_license_billing_prorate_prepaid_product_price'] = entity_import('rules_config', '{ "commerce_license_billing_prorate_prepaid_product_price" : {
"LABEL" : "Prorate the price of prepaid products",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-5",
"OWNER" : "rules",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [ "rules", "commerce_license_billing", "commerce_product_reference" ],
"ON" : { "commerce_product_calculate_sell_price" : [] },
"IF" : [
{ "NOT entity_is_of_bundle" : {
"entity" : [ "commerce-line-item" ],
"type" : "commerce_line_item",
"bundle" : { "value" : { "recurring" : "recurring" } }
}
},
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "commerce_license_billing_product_elligible" : { "commerce_product" : [ "commerce-line-item:commerce-product" ] } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "cl_billing_type"
}
},
{ "data_is" : {
"data" : [ "commerce-line-item:commerce-product:cl-billing-type" ],
"value" : "prepaid"
}
},
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "cl_billing_cycle_type"
}
},
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product:cl-billing-cycle-type" ],
"field" : "pce_async"
}
},
{ "data_is" : {
"data" : [ "commerce-line-item:commerce-product:cl-billing-cycle-type:pce-async" ],
"value" : 0
}
}
],
"DO" : [
{ "commerce_license_billing_prorate_product_line_item" : { "commerce_line_item" : [ "commerce_line_item" ] } }
]
}
}');
$items['commerce_license_billing_prorate_recurring_line_item'] = entity_import('rules_config', '{ "commerce_license_billing_prorate_recurring_line_item" : {
"LABEL" : "Prorate the price of a recurring line item",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-5",
"OWNER" : "rules",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [ "rules", "commerce_license_billing", "commerce_product_reference" ],
"ON" : { "commerce_product_calculate_sell_price" : [] },
"IF" : [
{ "entity_is_of_bundle" : {
"entity" : [ "commerce-line-item" ],
"type" : "commerce_line_item",
"bundle" : { "value" : { "recurring" : "recurring" } }
}
},
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:order" ],
"field" : "cl_billing_cycle"
}
},
{ "commerce_license_billing_product_prorating_eligible" : { "commerce_product" : [ "commerce-line-item:commerce-product" ] } }
],
"DO" : [
{ "commerce_license_billing_prorate_recurring_line_item" : { "commerce_line_item" : [ "commerce_line_item" ] } }
]
}
}');
$items['commerce_license_billing_create_recurring_orders'] = entity_import('rules_config', '{ "commerce_license_billing_create_recurring_orders" : {
"LABEL" : "Create recurring orders based on the initial order",
"PLUGIN" : "reaction rule",
"WEIGHT" : "10",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [ "commerce_license_billing", "commerce_payment" ],
"ON" : [ "commerce_payment_order_paid_in_full" ],
"IF" : [
{ "commerce_license_billing_order_elligible" : { "commerce_order" : [ "commerce_order" ] } }
],
"DO" : [
{ "commerce_license_billing_create_recurring_orders" : { "commerce_order" : [ "commerce_order" ] } }
]
}
}');
// For some reason, a crash occurs if the cardonfile module is missing when
// adding a default rule with it as the dependency.
if (module_exists('commerce_cardonfile')) {
$items['rules_commerce_license_billing_charge_recurring_order'] = entity_import('rules_config', '{ "rules_commerce_license_billing_charge_recurring_order" : {
"LABEL" : "Charge a recurring order",
"PLUGIN" : "reaction rule",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [ "rules", "commerce_payment", "commerce_cardonfile", "entity" ],
"ON" : [ "commerce_order_update" ],
"IF" : [
{ "NOT data_is" : {
"data" : [ "commerce-order:status" ],
"value" : [ "commerce-order-unchanged:status" ]
}
},
{ "data_is" : {
"data" : [ "commerce-order:status" ],
"value" : "recurring_payment_pending"
}
},
{ "commerce_payment_order_balance_comparison" : {
"commerce_order" : [ "commerce_order" ],
"operator" : "\u003E",
"value" : "0"
}
}
],
"DO" : [
{ "commerce_cardonfile_order_select_card" : {
"USING" : { "order" : [ "commerce-order" ] },
"PROVIDE" : { "select_card_response" : { "select_card_response" : "Select card response" } }
}
},
{ "commerce_cardonfile_order_charge_card" : {
"USING" : {
"order" : [ "commerce-order" ],
"charge" : [ "" ],
"select_card_response" : [ "select_card_response" ],
"card_data" : [ "" ]
},
"PROVIDE" : { "charge_card_response" : { "charge_card_response" : "charge Card Response" } }
}
}
]
}
}');
$items['rules_commerce_license_billing_update_order_charged'] = entity_import('rules_config', '{ "rules_commerce_license_billing_update_order_charged" : {
"LABEL" : "Update status of successfully charged recurring order",
"PLUGIN" : "reaction rule",
"WEIGHT" : "11",
"TAGS" : [ "Commerce License Billing" ],
"REQUIRES" : [ "commerce_order", "commerce_cardonfile" ],
"ON" : [ "commerce_cardonfile_charge_success" ],
"DO" : [
{ "commerce_order_update_status" : {
"commerce_order" : [ "order" ],
"order_status" : "completed"
}
}
]
}
}');
}
return $items;
}