AutoIt Requires Chilkat v11.0.0+
AutoIt
PayPal: Create a reusable payment link for a service
See more PayPal Examples
Offer an annual inspection for USD 90 through PayPal-hosted checkout. Store the returned resource ID with the catalog item and share the payment_link URL with customers.
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")
; Replace the thank-you URL with your business website. The same link can be shared
; with several customers.
; Create and persist this key once per business operation. On a timeout,
; retry the same request with its saved key, not a newly generated one.
$oCrypt = ObjCreate("Chilkat.Crypt2")
Local $sRequestId = $oCrypt.GenerateUuid()
$oHttp.SetRequestHeader "PayPal-Request-Id",$sRequestId
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("integration_mode","LINK")
$oBody.UpdateString("type","BUY_NOW")
$oBody.UpdateString("reusable","MULTIPLE")
$oBody.UpdateString("return_url","https://merchant.example/thank-you")
$oBody.UpdateString("line_items[0].name","Annual inspection")
$oBody.UpdateString("line_items[0].unit_amount.currency_code","USD")
$oBody.UpdateString("line_items[0].unit_amount.value","90.00")
$bSuccess = $oHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources",$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
$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("Catalog payment resource ID: " & $oResult.StringOf("id") & @CRLF)
; Link order is not fixed. Find the customer-facing link to copy into an email.
Local $iLinkIndex = 0
While ($iLinkIndex < $oResult.SizeOfArray("links"))
$oResult.I = $iLinkIndex
If ($oResult.StringOfEquals("links[i].rel","payment_link",True)) Then
ConsoleWrite("Share this payment link: " & $oResult.StringOf("links[i].href") & @CRLF)
EndIf
$iLinkIndex = $iLinkIndex + 1
Wend