PowerBuilder Stripe: Pay an Invoice

Back to Index

Attempts payment on an invoice out of the normal collection schedule.

Documentation: https://stripe.com/docs/api/curl#pay_invoice

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/pay \
   -u STRIPE_SECRET_KEY: \
   -X POST

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
oleobject loo_JsonResponse
string ls_Id
string ls_Object
integer li_Amount_due
integer li_Application_fee
integer li_Attempt_count
integer li_Attempted
string ls_Billing
string ls_Charge
integer li_Closed
string ls_Currency
string ls_Customer
integer li_Date
integer li_Description
integer li_Discount
integer li_Due_date
integer li_Ending_balance
integer li_Forgiven
integer li_LinesHas_more
string ls_LinesObject
string ls_LinesUrl
integer li_Livemode
integer li_Next_payment_attempt
string ls_Number
integer li_Paid
integer li_Period_end
integer li_Period_start
integer li_Receipt_number
integer li_Starting_balance
integer li_Statement_descriptor
integer li_Subscription
integer li_Subtotal
integer li_Tax
integer li_Tax_percent
integer li_Total
integer li_Webhooks_delivered_at
integer li_Last_payment_attempt
integer i
integer li_Count_i
integer li_Amount
string ls_Description_str
integer li_Discountable
integer li_PeriodStart
integer li_PeriodEnd
string ls_PlanId
string ls_PlanObject
integer li_PlanAmount
integer li_PlanCreated
string ls_PlanCurrency
string ls_PlanInterval
integer li_PlanInterval_count
integer li_PlanLivemode
string ls_PlanName
integer li_PlanStatement_descriptor
integer li_PlanTrial_period_days
integer li_Proration
integer li_Quantity
string ls_Subscription_item
string ls_Type

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

//  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/pay
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.stripe.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("STRIPE_SECRET_KEY","")

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

li_Success = loo_Rest.FullRequestNoBodySb("POST","/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/pay",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponseBody
    return
end if

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

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_Id = loo_JsonResponse.StringOf("id")
ls_Object = loo_JsonResponse.StringOf("object")
li_Amount_due = loo_JsonResponse.IntOf("amount_due")
li_Application_fee = loo_JsonResponse.IsNullOf("application_fee")
li_Attempt_count = loo_JsonResponse.IntOf("attempt_count")
li_Attempted = loo_JsonResponse.BoolOf("attempted")
ls_Billing = loo_JsonResponse.StringOf("billing")
ls_Charge = loo_JsonResponse.StringOf("charge")
li_Closed = loo_JsonResponse.BoolOf("closed")
ls_Currency = loo_JsonResponse.StringOf("currency")
ls_Customer = loo_JsonResponse.StringOf("customer")
li_Date = loo_JsonResponse.IntOf("date")
li_Description = loo_JsonResponse.IsNullOf("description")
li_Discount = loo_JsonResponse.IsNullOf("discount")
li_Due_date = loo_JsonResponse.IsNullOf("due_date")
li_Ending_balance = loo_JsonResponse.IsNullOf("ending_balance")
li_Forgiven = loo_JsonResponse.BoolOf("forgiven")
li_LinesHas_more = loo_JsonResponse.BoolOf("lines.has_more")
ls_LinesObject = loo_JsonResponse.StringOf("lines.object")
ls_LinesUrl = loo_JsonResponse.StringOf("lines.url")
li_Livemode = loo_JsonResponse.BoolOf("livemode")
li_Next_payment_attempt = loo_JsonResponse.IntOf("next_payment_attempt")
ls_Number = loo_JsonResponse.StringOf("number")
li_Paid = loo_JsonResponse.BoolOf("paid")
li_Period_end = loo_JsonResponse.IntOf("period_end")
li_Period_start = loo_JsonResponse.IntOf("period_start")
li_Receipt_number = loo_JsonResponse.IsNullOf("receipt_number")
li_Starting_balance = loo_JsonResponse.IntOf("starting_balance")
li_Statement_descriptor = loo_JsonResponse.IsNullOf("statement_descriptor")
li_Subscription = loo_JsonResponse.IsNullOf("subscription")
li_Subtotal = loo_JsonResponse.IntOf("subtotal")
li_Tax = loo_JsonResponse.IsNullOf("tax")
li_Tax_percent = loo_JsonResponse.IsNullOf("tax_percent")
li_Total = loo_JsonResponse.IntOf("total")
li_Webhooks_delivered_at = loo_JsonResponse.IsNullOf("webhooks_delivered_at")
li_Last_payment_attempt = loo_JsonResponse.IsNullOf("last_payment_attempt")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("lines.data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Id = loo_JsonResponse.StringOf("lines.data[i].id")
    ls_Object = loo_JsonResponse.StringOf("lines.data[i].object")
    li_Amount = loo_JsonResponse.IntOf("lines.data[i].amount")
    ls_Currency = loo_JsonResponse.StringOf("lines.data[i].currency")
    ls_Description_str = loo_JsonResponse.StringOf("lines.data[i].description")
    li_Discountable = loo_JsonResponse.BoolOf("lines.data[i].discountable")
    li_Livemode = loo_JsonResponse.BoolOf("lines.data[i].livemode")
    li_PeriodStart = loo_JsonResponse.IntOf("lines.data[i].period.start")
    li_PeriodEnd = loo_JsonResponse.IntOf("lines.data[i].period.end")
    ls_PlanId = loo_JsonResponse.StringOf("lines.data[i].plan.id")
    ls_PlanObject = loo_JsonResponse.StringOf("lines.data[i].plan.object")
    li_PlanAmount = loo_JsonResponse.IntOf("lines.data[i].plan.amount")
    li_PlanCreated = loo_JsonResponse.IntOf("lines.data[i].plan.created")
    ls_PlanCurrency = loo_JsonResponse.StringOf("lines.data[i].plan.currency")
    ls_PlanInterval = loo_JsonResponse.StringOf("lines.data[i].plan.interval")
    li_PlanInterval_count = loo_JsonResponse.IntOf("lines.data[i].plan.interval_count")
    li_PlanLivemode = loo_JsonResponse.BoolOf("lines.data[i].plan.livemode")
    ls_PlanName = loo_JsonResponse.StringOf("lines.data[i].plan.name")
    li_PlanStatement_descriptor = loo_JsonResponse.IsNullOf("lines.data[i].plan.statement_descriptor")
    li_PlanTrial_period_days = loo_JsonResponse.IsNullOf("lines.data[i].plan.trial_period_days")
    li_Proration = loo_JsonResponse.BoolOf("lines.data[i].proration")
    li_Quantity = loo_JsonResponse.IntOf("lines.data[i].quantity")
    li_Subscription = loo_JsonResponse.IsNullOf("lines.data[i].subscription")
    ls_Subscription_item = loo_JsonResponse.StringOf("lines.data[i].subscription_item")
    ls_Type = loo_JsonResponse.StringOf("lines.data[i].type")
    i = i + 1
loop


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse

Sample JSON Response Body

{
  "id": "in_1BnETLGswQrCoh0X6M67Qy9c",
  "object": "invoice",
  "amount_due": 0,
  "application_fee": null,
  "attempt_count": 0,
  "attempted": true,
  "billing": "charge_automatically",
  "charge": "ch_1BnETLGswQrCoh0XYoMbCKZ3",
  "closed": false,
  "currency": "usd",
  "customer": "cus_CBbggkUyLoz3pe",
  "date": 1516662783,
  "description": null,
  "discount": null,
  "due_date": null,
  "ending_balance": null,
  "forgiven": false,
  "lines": {
    "data": [
      {
        "id": "sub_CBbgC3EaFZqN3Q",
        "object": "line_item",
        "amount": 999,
        "currency": "usd",
        "description": "1x Silver Express (at $9.99)",
        "discountable": true,
        "livemode": true,
        "metadata": {},
        "period": {
          "start": 1521760383,
          "end": 1524438783
        },
        "plan": {
          "id": "gold",
          "object": "plan",
          "amount": 2000,
          "created": 1516662783,
          "currency": "usd",
          "interval": "month",
          "interval_count": 1,
          "livemode": false,
          "metadata": {},
          "name": "T-shirt",
          "statement_descriptor": null,
          "trial_period_days": null
        },
        "proration": false,
        "quantity": 1,
        "subscription": null,
        "subscription_item": "si_CBbgZxCVF3Ha7P",
        "type": "subscription"
      }
    ],
    "has_more": false,
    "object": "list",
    "url": "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines"
  },
  "livemode": false,
  "metadata": {},
  "next_payment_attempt": 1516666383,
  "number": "330a34b8d5-0001",
  "paid": true,
  "period_end": 1516662783,
  "period_start": 1516662783,
  "receipt_number": null,
  "starting_balance": 0,
  "statement_descriptor": null,
  "subscription": null,
  "subtotal": 0,
  "tax": null,
  "tax_percent": null,
  "total": 0,
  "webhooks_delivered_at": null,
  "last_payment_attempt": null
}