Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

PayPal: Suspend an active subscription

See more PayPal Examples

Pause future billing after checking that the subscription is active. Save the reason with the customer support record.

PayPal documentation

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  See Unlock Chilkat before making requests.
;  For the merchant's internal backoffice application. Load the sandbox token
;  from the merchant's credential store. Keep it out of publicly distributed apps.
;  See Get a PayPal access token.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")

$oHttp.SetUrlVar("id","SUBSCRIPTION_ID")

$bSuccess = $oHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}",$oResp)
If ($bSuccess <> True) Then
    ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
    Exit
EndIf

If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    $oErrorInfo = ObjCreate("Chilkat.JsonObject")
    $oErrorInfo.Load($oResp.BodyStr)
    ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
    ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
    Exit
EndIf

$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsedResult = $oResult.Load($oResp.BodyStr)
If ($bParsedResult <> True) Then
    ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
    Exit
EndIf

If ($oResult.StringOfEquals("status","ACTIVE",True) <> True) Then
    ConsoleWrite("Subscription status is " & $oResult.StringOf("status") & ". No change made." & @CRLF)
    Exit
EndIf

$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("reason","Customer requested a billing pause.")
$bSuccess = $oHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/suspend",$oBody,"application/json",$oResp)
If ($bSuccess <> True) Then
    ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
    Exit
EndIf

If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    $oChangeError = ObjCreate("Chilkat.JsonObject")
    $oChangeError.Load($oResp.BodyStr)
    ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oChangeError.StringOf("name") & " " & $oChangeError.StringOf("details[0].issue") & @CRLF)
    ConsoleWrite("PayPal debug ID: " & $oChangeError.StringOf("debug_id") & @CRLF)
    Exit
EndIf

ConsoleWrite("PayPal accepted the subscription change." & @CRLF)