This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Coupons in Recurly



Overview

The following operations allow you to work with coupons. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with coupons, see Sample configuration.

OperationDescription

createCoupon

Creates a coupon.

getCouponByCodeRetrieves a coupon by code.
listCouponsRetrieves all the coupons.

Operation details

This section provides further details on the operations related to coupons.

Creating a coupon

The createCoupon operation creates a coupon.

createCoupon
<recurly.createCoupon>
    <planCodes>{$ctx:planCodes}</planCodes>
    <hostedDescription>{$ctx:hostedDescription}</hostedDescription>
    <discountType>{$ctx:discountType}</discountType>
    <appliesForMonths>{$ctx:appliesForMonths}</appliesForMonths>
    <name>{$ctx:name}</name>
    <discountInCents>{$ctx:discountInCents}</discountInCents>
    <maxRedemptions>{$ctx:maxRedemptions}</maxRedemptions>
    <redeemByDate>{$ctx:redeemByDate}</redeemByDate>
    <couponCode>{$ctx:couponCode}</couponCode>
    <discountPercent>{$ctx:discountPercent}</discountPercent>
    <singleUse>{$ctx:singleUse}</singleUse>
    <invoiceDescription>{$ctx:invoiceDescription}</invoiceDescription>
	<appliesToAllPlans>{$ctx:appliesToAllPlans}</appliesToAllPlans>
</recurly.createCoupon>
Properties
  • couponCode: Required - The ID of the coupon to be created.
  • name: Required - The name of the coupon.
  • discountType: Required - The type of the discount as percent or dollars.
  • planCodes: The array of plan codes the coupon applies to.
  • hostedDescription: The description of the coupon on the hosted payment page.
  • appliesForMonths: The number of months for which the coupon is valid after redemption.
  • discountInCents: The mapping of discount amounts by currency if discount_type is "dollars".
  • maxRedemptions: The maximum number of accounts for which the coupon can be used.
  • redeemByDate: The last date to redeem the coupon.
  • discountPercent: The discount percentage if discount_type is "percent".
  • singleUse: The boolean flag indicating that the coupon can be used only once.
  • invoiceDescription: The description of the coupon on the invoice.
  • appliesToAllPlans: The boolean flag indicating whether the coupon is applied for all the plans.
Sample request

Following is a sample REST/XML request that can be handled by the createCoupon operation.

Sample Request for createCoupon
<createCoupon>
   <apiUrl>https://virasoft.recurly.com</apiUrl>
   <apiKey>3eee78b99ffa4206a0374615f430f50a</apiKey>
   <couponCode>test_coupon</couponCode>
   <name>Test Coupon</name>
   <discountType>dollars</discountType>
   <discountPercent></discountPercent>
   <discountInCents>
      <values>
         <USD>500</USD>
         <EUR>400</EUR>
         <GBP>300</GBP>
      </values>
   </discountInCents>
   <planCodes>
      <values>
         <plan_code>1</plan_code>
         <plan_code>2</plan_code>
      </values>
   </planCodes>
   <hostedDescription>hosted description</hostedDescription>
   <invoiceDescription>invoice description</invoiceDescription>
   <appliesForMonths>2</appliesForMonths>
   <maxRedemptions>10</maxRedemptions>
   <redeemByDate>2015-03-01</redeemByDate>
   <singleUse>false</singleUse>
   <appliesToAllPlans>false</appliesToAllPlans>
</createCoupon>
Related Recurly documentation

https://docs.recurly.com/api/coupons#create-coupon

Retrieving a coupon by code

The getCouponByCode operation retrieves a coupon by code.

getCouponByCode
<recurly.getCouponByCode>
	<couponCode>{$ctx:couponCode}</couponCode>
</recurly.getCouponByCode>
Properties
  • couponCode: Required - The ID of the coupon to be fetched.
Sample request

Following is a sample REST/XML request that can be handled by the getCouponByCode operation.

getCouponByCode
<getCouponByCode>
   <apiUrl>https://virasoft.recurly.com</apiUrl>
   <apiKey>3eee78b99ffa4206a0374615f430f50a</apiKey>
   <couponCode>gold_special</couponCode>
</getCouponByCode>
Related Recurly documentation

https://docs.recurly.com/api/coupons#lookup-coupon

Retrieving all the coupons

The listCoupons operation retrieves all the coupons.

listCoupons
<recurly.listCoupons>
    <cursor>{$ctx:cursor}</cursor>
    <state>{$ctx:state}</state>
	<perPage>{$ctx:perPage}</perPage>
</recurly.listCoupons>
Properties
  • cursor: The cursor value retrieved from the Link header for requesting a specific page.
  • state: The state of the coupons.
  • perPage: The number of records to be retrieved per page.
Sample request

Following is a sample REST/XML request that can be handled by the listCoupons operation.

listCoupons
<listCoupons>
   <apiUrl>https://virasoft.recurly.com</apiUrl>
   <apiKey>3eee78b99ffa4206a0374615f430f50a</apiKey>
   <cursor></cursor>
   <state>redeemable</state>
   <perPage>1</perPage>
</listCoupons>
Related Recurly documentation

https://docs.recurly.com/api/coupons#list-coupons

Sample configuration

Following is a sample proxy service that illustrates how to connect to Recurly with the init operation and use the createCoupon operation. The sample request for this proxy can be found in the createCoupon sample request. You can use this sample as a template for using other operations in this category.

Sample Proxy
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="recurly_createCoupon"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <property name="apiUrl" expression="//apiUrl/text()"/>
         <property name="apiKey" expression="//apiKey/text()"/>
         <property name="planCodes" expression="//planCodes/values"/>
         <property name="hostedDescription" expression="//hostedDescription/text()"/>
         <property name="discountType" expression="//discountType/text()"/>
         <property name="appliesForMonths" expression="//appliesForMonths/text()"/>
         <property name="name" expression="//name/text()"/>
         <property name="discountInCents" expression="//discountInCents/values"/>
         <property name="maxRedemptions" expression="//maxRedemptions/text()"/>
         <property name="redeemByDate" expression="//redeemByDate/text()"/>
         <property name="couponCode" expression="//couponCode/text()"/>
         <property name="discountPercent" expression="//discountPercent/text()"/>
         <property name="singleUse" expression="//singleUse/text()"/>
         <property name="invoiceDescription" expression="//invoiceDescription/text()"/>
         <property name="appliesToAllPlans" expression="//appliesToAllPlans/text()"/>
         <recurly.init>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
            <apiKey>{$ctx:apiKey}</apiKey>
         </recurly.init>
         <recurly.createCoupon>
            <planCodes>{$ctx:planCodes}</planCodes>
            <hostedDescription>{$ctx:hostedDescription}</hostedDescription>
            <discountType>{$ctx:discountType}</discountType>
            <appliesForMonths>{$ctx:appliesForMonths}</appliesForMonths>
            <name>{$ctx:name}</name>
            <discountInCents>{$ctx:discountInCents}</discountInCents>
            <maxRedemptions>{$ctx:maxRedemptions}</maxRedemptions>
            <redeemByDate>{$ctx:redeemByDate}</redeemByDate>
            <couponCode>{$ctx:couponCode}</couponCode>
            <discountPercent>{$ctx:discountPercent}</discountPercent>
            <singleUse>{$ctx:singleUse}</singleUse>
            <invoiceDescription>{$ctx:invoiceDescription}</invoiceDescription>
            <appliesToAllPlans>{$ctx:appliesToAllPlans}</appliesToAllPlans>
         </recurly.createCoupon>
         <respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>