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

PayPal: Save a payable invoice QR code as a PNG

See more PayPal Examples

Generate a 300-pixel payment QR code for a sent, payable invoice. Decode the base64 image into a PNG for a printed invoice; the code opens the payment page, and is not proof of payment.

PayPal documentation

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = 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.
Dim http As New Chilkat.Http
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
Dim resp As New Chilkat.HttpResponse

'  Use a sent, payable invoice. Width and height are JSON numbers, in pixels.

http.SetUrlVar("id","INVOICE_ID")
Dim body As New Chilkat.JsonObject
body.UpdateInt("width",300)
body.UpdateInt("height",300)
body.UpdateString("action","pay")

success = http.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/generate-qr-code",body,"application/json",resp)
If (success <> True) Then
    Debug.WriteLine("No HTTP response: " & http.LastErrorText)
    Exit Sub
End If

If ((resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    Dim errorInfo As New Chilkat.JsonObject
    errorInfo.Load(resp.BodyStr)
    Debug.WriteLine("HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue"))
    Debug.WriteLine("PayPal debug ID: " & errorInfo.StringOf("debug_id"))
    Exit Sub
End If


Dim result As New Chilkat.JsonObject
Dim parsed As Boolean = result.Load(resp.BodyStr)
If (parsed <> True) Then
    Debug.WriteLine("Expected a JSON response; HTTP " & resp.StatusCode)
    Exit Sub
End If

Dim png As New Chilkat.BinData
If (result.HasMember("image") <> True) Then
    Debug.WriteLine("QR response did not contain an image.")
    Exit Sub
End If

Dim decoded As Boolean = png.AppendEncoded(result.StringOf("image"),"base64")
If (decoded <> True) Then
    Debug.WriteLine("Invalid base64 image.")
    Exit Sub
End If

Dim savedImage As Boolean = png.WriteFile("paypal-invoice-qr.png")
If (savedImage <> True) Then
    Debug.WriteLine("Could not write the invoice QR image.")
    Exit Sub
End If

Debug.WriteLine("Saved paypal-invoice-qr.png.")