AutoIt Requires Chilkat v11.0.0+
AutoIt
PayPal: Look up a subscription and its recent payments
See more PayPal Examples
Start with the PayPal subscription ID saved with the local customer. Display its status and next billing time, then list transactions for the previous 30 days with each gross amount and currency.
Chilkat AutoIt Downloads
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
ConsoleWrite("Status: " & $oResult.StringOf("status") & @CRLF)
ConsoleWrite("Next billing: " & $oResult.StringOf("billing_info.next_billing_time") & @CRLF)
$oNow = ObjCreate("Chilkat.CkDateTime")
$oNow.SetFromCurrentSystemTime()
$oQuery = ObjCreate("Chilkat.JsonObject")
$oQuery.UpdateString("end_time",$oNow.GetAsTimestamp(False))
$oNow.AddDays(-30)
$oQuery.UpdateString("start_time",$oNow.GetAsTimestamp(False))
$bSuccess = $oHttp.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/transactions",$oQuery,$oResp)
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
Exit
EndIf
If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
$oHistoryError = ObjCreate("Chilkat.JsonObject")
$oHistoryError.Load($oResp.BodyStr)
ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oHistoryError.StringOf("name") & " " & $oHistoryError.StringOf("details[0].issue") & @CRLF)
ConsoleWrite("PayPal debug ID: " & $oHistoryError.StringOf("debug_id") & @CRLF)
Exit
EndIf
$oHistory = ObjCreate("Chilkat.JsonObject")
Local $bParsedHistory = $oHistory.Load($oResp.BodyStr)
If ($bParsedHistory <> True) Then
ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
Exit
EndIf
Local $i = 0
While ($i < $oHistory.SizeOfArray("transactions"))
$oHistory.I = $i
ConsoleWrite($oHistory.StringOf("transactions[i].time") & " " & $oHistory.StringOf("transactions[i].id") & " " & $oHistory.StringOf("transactions[i].status") _
& " " & $oHistory.StringOf("transactions[i].amount_with_breakdown.gross_amount.value") & " " & $oHistory.StringOf("transactions[i].amount_with_breakdown.gross_amount.currency_code") & @CRLF)
$i = $i + 1
Wend