How to apply coupon in commerce order programmatically? I'm working on creating web services for mobile applications to use drupal as backend. When ever the user applying a coupon code through mobile application, I'll get the coupon code through web services as JSON data.

So, How can I validate and apply the coupon to the order programmatically.
I found the below answer from StackExchange (programmatically add line item of commerce_discount type to order). But, what value I need to pass for $discount_name. And how can I get it?

commerce_discount_fixed_amount(EntityDrupalWrapper $wrapper, $discount_name);
When you are creating a discount, you will enter the name and the system will automatically generate machine-name. You need to use the machine name as an argument for commerce_discount_fixed_amount() function.

Here's a screenshot:



Here's how you would use it:

commerce_discount_fixed_amount(EntityDrupalWrapper $wrapper, 'discount_test_discount');