You can link an Offer to a Subscription while creating the Subscription using this API.
Use the below endpoint to create a new subscription link.
Curl PHP Node.JS Python Go Response
Copy curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/subscriptions \
-H "Content-Type: application/json" \
-d '{
"plan_id": "plan_00000000000001",
"total_count": 12,
"quantity": 1,
"start_at": 1561852800,
"expire_by": 1561939199,
"customer_notify": 1,
"addons": [
{
"item": {
"name": "Delivery charges",
"amount": 30000,
"currency": "INR"
}
}
],
"offer_id":"offer_JHD834hjbxzhd38d",
"notes": {
"notes_key_1":"Tea, Earl Grey, Hot",
"notes_key_2":"Tea, Earl Grey… decaf."
},
"notify_info":{
"notify_phone": "9123456789",
"notify_email": "gaurav.kumar@example.com"
}
}'
Copy $api = new Api($key_id , $secret );
$api ->subscription->create(array ('plan_id' => 'plan_HoYg68p5kmuvzD' ,'total_count' => 12 ,'quantity' => 1 ,'expire_by' => 1633237807 ,'customer_notify' => 1 , 'addons' => array (array ('item' =>array ('name' => 'Delivery charges' ,'amount' => 30000 ,'currency' => 'INR' ))),'notes' =>array ('notes_key_1' =>'Tea, Earl Grey, Hot' ,'notes_key_2' =>'Tea, Earl Grey… decaf.' ),'notify_info' =>array ('notify_phone' => '9123456789' ,'notify_email' => 'gaurav.kumar@example.com' )));
Copy var instance = new Razorpay ({ key_id : 'YOUR_KEY_ID' , key_secret : 'YOUR_SECRET' })
instance.subscriptions .create ({
plan_id : "plan_HoYg68p5kmuvzD" ,
total_count : 12 ,
quantity : 1 ,
expire_by : 1633237807 ,
customer_notify : 1 ,
addons : [
{
item : {
name : "Delivery charges" ,
amount : 30000 ,
currency : "INR"
}
}
],
notes : {
notes_key_1 : "Tea, Earl Grey, Hot" ,
notes_key_2 : "Tea, Earl Grey… decaf."
},
notify_info : {
notify_phone : 9123456789 ,
notify_email : "gaurav.kumar@example.com"
}
})
Copy import razorpay
client = razorpay.Client(auth=("YOUR_ID" , "YOUR_SECRET" ))
client.subscription.create({
'plan_id' : 'plan_HoYg68p5kmuvzD' ,
'total_count' : 12 ,
'quantity' : 1 ,
'expire_by' : 1633237807 ,
'customer_notify' : 1 ,
'addons' : [{'item' : {'name' : 'Delivery charges' , 'amount' : 30000 ,
'currency' : 'INR' }}],
'notes' : {'notes_key_1' : 'Tea, Earl Grey, Hot' ,
'notes_key_2' : 'Tea, Earl Grey\xe2\x80\xa6 decaf.' },
'notify_info' : {'notify_phone' : 9123456789 ,
'notify_email' : 'gaurav.kumar@example.com' }
})
Copy import ( razorpay "github.com/razorpay/razorpay-go" )
client := razorpay.NewClient("YOUR_KEY_ID" , "YOUR_SECRET" )
data := map [string ]interface {}{
"plan_id" : "plan_00000000000001" ,
"total_count" : 12 ,
"quantity" : 1 ,
"start_at" : 1561852800 ,
"expire_by" : 1561939199 ,
"customer_notify" : 1 ,
"addons" : []interface {}{
map [string ]interface {}{
"item" : map [string ]interface {}{
"name" : "Delivery charges" ,
"amount" : 30000 ,
"currency" : "INR" ,
},
},
},
"offer_id" :"offer_JHD834hjbxzhd38d" ,
"notes" : map [string ]interface {}{
"notes_key_1" :"Tea, Earl Grey, Hot" ,
"notes_key_2" :"Tea, Earl Grey… decaf." ,
},
"notify_info" :map [string ]interface {}{
"notify_phone" : "9123456789" ,
"notify_email" : "gaurav.kumar@example.com" ,
},
}
body, err := client.Subscription.Create(data, nil )
Copy {
"id" : "sub_00000000000002" ,
"entity" : "subscription" ,
"plan_id" : "plan_00000000000001" ,
"status" : "created" ,
"current_start" : null ,
"current_end" : null ,
"ended_at" : null ,
"quantity" : 1 ,
"notes" : {
"notes_key_1" : "Tea, Earl Grey, Hot" ,
"notes_key_2" : "Tea, Earl Grey… decaf."
} ,
"charge_at" : 1580453311 ,
"start_at" : 1580453311 ,
"end_at" : 1587061800 ,
"auth_attempts" : 0 ,
"total_count" : 12 ,
"paid_count" : 0 ,
"customer_notify" : true ,
"created_at" : 1580283117 ,
"expire_by" : 1581013800 ,
"short_url" : "https://rzp.io/i/m0y0f" ,
"has_scheduled_changes" : false ,
"change_scheduled_at" : null ,
"source" : "api" ,
"offer_id" : "offer_JHD834hjbxzhd38d" ,
"remaining_count" : 12
}