0

Stripe response 200 OK There was an errorColumn 'available_currency' cannot be null

please help how can I get json request "available" array and "pending" array store in a variable then store in DB

this is stripe json

{
  "id": "evt_1Muxxxxxxxxxxxxxxx",
  "object": "event",
  "api_version": "2022-11-15",
  "created": 1680827076,
  "data": {
    "object": {
      "object": "balance",
      "available": [
        {
          "amount": 7642,
          "currency": "gbp",
          "source_types": {
            "card": 7642
          }
        }
      ],
      "livemode": false,
      "pending": [
        {
          "amount": 213601,
          "currency": "gbp",
          "source_types": {
            "card": 213601
          }
        }
      ]
    }
  },
  "livemode": false,
  "pending_webhooks": 1,
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "balance.available"
}
case 'balance.available':
    $balance = $event->data->object; // contains a \Stripe\PaymentMethod

    $available_currency = $event->data->object->available->currency;
    $available_card = $event->data->object->available->source_types->card;

    $pending_amount = $event->data->object->pending->amount;
    $pending_currency = $event->data->object->pending->currency;
    $pending_card = $event->data->object->pending->source_types->card;


    $stmt_balance = $con->prepare("INSERT INTO tbl_balance (available_currency, available_card,   pending_amount, pending_currency, pending_card) VALUES (?, ?, ?, ?, ?)");
    $stmt_balance->bind_param("sidsi", $available_currency, $available_card, $pending_amount, $pending_currency, $pending_card);
    // $stmt->execute();
    if (!$stmt_balance->execute()) {
      # code...
      echo 'There was an error'.mysqli_error($con);
    }    
    $stmt_balance->close();
    $con->close();
    // handlePaymentMethodAttached($paymentMethod);
    break;

Stripe response 200 OK There was an errorColumn 'available_currency' cannot be null

please help how can I get json request "available" array and "pending" array store in a variable then store in DB

  • 1
    `$event->data->object->available` is an array. You probably want `$event->data->object->available[0]->currency`. This of course then begs the question -- what happens if there's more than one currency? – Alex Howansky Apr 07 '23 at 16:12
  • In the JSON, the `available` property is an array, not an object. The first index of that array then contains the object. – ADyson Apr 07 '23 at 16:12
  • $available_amount = $event->data->object->available[0]->amount; $available_currency = $event->data->object->available[1]->currency; $available_card = $event->data->object->available->source_types[0]->card; $pending_amount = $event->data->object->pending[0]->amount; $pending_currency = $event->data->object->pending[1]->currency; $pending_card = $event->data->object->pending->source_types[0]->card; still i face There was an errorColumn 'available_currency' cannot be null – dagemawi alemayhu Apr 07 '23 at 16:32
  • Why available[1]? Nobody suggested that. And what makes you think such an index exists? You can see clearly from the JSON that the array contains only one object. Also have you switched off errors and warnings in your php code? Because you should get a warning when you try to access an index which doesn't exist. Check your php error log file maybe – ADyson Apr 07 '23 at 18:25

0 Answers0