Chilkat Online Tools

PowerBuilder / Razorpay APIs / Update Subscription

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "username"
loo_Http.Password = "password"

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "plan_id": "{plan_id}",
//   "quantity": 3,
//   "remaining_count": 6,
//   "schedule_change_at": "now",
//   "customer_notify": 1,
//   "offer_id": "{offer_id}"
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("plan_id","{plan_id}")
loo_Json.UpdateInt("quantity",3)
loo_Json.UpdateInt("remaining_count",6)
loo_Json.UpdateString("schedule_change_at","now")
loo_Json.UpdateInt("customer_notify",1)
loo_Json.UpdateString("offer_id","{offer_id}")

loo_Http.SetRequestHeader("Content-Type","application/json")

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("PATCH","https://api.razorpay.com/v1/subscriptions/{sub_id}",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody

Curl Command

curl -X PATCH
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
  "plan_id": "{plan_id}",
  "quantity": 3,
  "remaining_count": 6,
  "schedule_change_at": "now",
  "customer_notify": 1,
  "offer_id":"{offer_id}"
}'
https://api.razorpay.com/v1/subscriptions/{sub_id}

Postman Collection Item JSON

{
  "name": "Update Subscription",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"plan_id\": \"{plan_id}\",\n  \"quantity\": 3,\n  \"remaining_count\": 6,\n  \"schedule_change_at\": \"now\",\n  \"customer_notify\": 1,\n  \"offer_id\":\"{offer_id}\"\n}"
    },
    "url": {
      "raw": "https://api.razorpay.com/v1/subscriptions/{sub_id}",
      "protocol": "https",
      "host": [
        "api",
        "razorpay",
        "com"
      ],
      "path": [
        "v1",
        "subscriptions",
        "{sub_id}"
      ]
    },
    "description": "You can update a specific subscription created by you using the <a href=\"https://razorpay.com/docs/api/subscriptions/#update-a-subscription\" target=\"_blank\">Update a Subscription API</a>."
  },
  "response": [
  ]
}