Drupal Commerce: discount for line items based on user's values? I need to have different discount rates for every customer.

I added a textfield in the user profile, where I store a Json object with all the discounts (there is a little GUI to manipulate it), so, for example, I can have this situation:

{
    'product_B': 20,
    'product_A': 15,
    'product_C': 0
}


This means that this customer will have a fixed discount for all commerce_products of type A, 15 on type B and 0 on type C.

I got stuck in the Rules configuration: I created a rule for the Subtract an amount from the unit price event; In the condition, i just check that the user and the line item match few pre-requisites, and it works, but I cant get the line_item details in the action:

// My action
global $user;
$ul = user_load($user-&gt;uid);
if(isset($ul-&gt;field_discounts))
{
  $user_discounts = field_get_items('user', $ul, 'field_discounts');
  /*
   * Here i have to get few info of the current commerce_product/commerce_line_item
   * in order to calculate the correct $item_discount
   * */
  $discount = ((int)$item_discount * $value) / 100;
  return $discount;
}
return 0;


So the question is: inside that PHP block, how to get the current line item?
I don't think the line item will be exposed to the PHP block, and I doubt there'll be anything in scope to get a reference back to it. 

You might need to create your own Rules action. It's pretty simple, and you can copy most of what you need from commerce_line_item_unit_price_subtract(), which does have access to the line item entity.

hook_rules_action_info() would be a good place to start.