PHP полоса массив - PullRequest
       9

PHP полоса массив

0 голосов
/ 06 сентября 2018

Итак, у меня есть следующий массив, который исходит от полосового крючка.

Я знаю, что могу получить идентификатор клиента, сделав это

$input = file_get_contents('php://input');
$json = json_decode($input, TRUE);
$customer = $json['data']['object']['customer'];
Echo $customer

Но я не могу понять, как извлечь метку времени из этого бита:

"period": {
"end": 1536264305,
"start": 1536177905
 },

Я чувствую, что Iv перепробовал все, но не может получить доступ к этой части массива, чтобы получить их в пригодные для использования переменные? Для установки даты окончания подписки

Заранее спасибо всем, кто может мне помочь!

Полный массив:

 {
    "created": 1326853478,
    "livemode": false,
    "id": "invoice.payment_00000000000000",
    "type": "invoice.payment_succeeded",
    "object": "event",
    "request": null,
    "pending_webhooks": 1,
    "api_version": "2017-08-15",
    "data": {
        "object": {
            "id": "in_00000000000000",
            "object": "invoice",
            "amount_due": 0,
            "amount_paid": 0,
            "amount_remaining": 0,
              "application_fee": null,
              "attempt_count": 0,
              "attempted": true,
              "auto_advance": false,
              "billing": "charge_automatically",
              "billing_reason": "subscription_update",
              "charge": "_00000000000000",
              "closed": true,
              "currency": "gbp",
              "customer": "cus_00000000000000",
            "date": 1535918681,
            "description": null,
            "discount": null,
            "due_date": null,
            "ending_balance": 0,
            "forgiven": false,
            "hosted_invoice_url":        "https://pay.stripe.com/invoice/invst_WeVOimsiIrwCiJALFNVBIPd9Xl",
            "invoice_pdf": "https://pay.stripe.com/invoice/invst_WeVOimsiIrwCiJALFNVBIPd9Xl/pdf",
            "lines": {
                "data": [
                    {
                        "id": "sub_00000000000000",
                        "object": "line_item",
                        "amount": 0,
                        "currency": "gbp",
                        "description": null,
                        "discountable": true,
                        "livemode": false,
                        "metadata": {
                                    },
                        "period": {
                            "end": 1536264305,
                            "start": 1536177905
                            },
                        "plan": {
                            "id": "1_00000000000000",
                            "object": "plan",
                            "active": true,
                            "aggregate_usage": null,
                            "amount": 0,
                            "billing_scheme": "per_unit",
                            "created": 1536098766,
                            "currency": "gbp",
                            "interval": "day",
                            "interval_count": 1,
                            "livemode": false,
                            "metadata": {
                                },
                            "name": "Monthly (1)",
                            "nickname": null,
                            "product": "prod_00000000000000",
                            "statement_descriptor": null,
                            "tiers": null,
                            "tiers_mode": null,
                            "transform_usage": null,
                            "trial_period_days": null,
                            "usage_type": "licensed"
                        },
                    "proration": false,
                    "quantity": 1,
                    "subscription": null,
                    "subscription_item": "si_00000000000000",
                    "type": "subscription"
                }
            ],
    "has_more": false,
    "object": "list",
    "url": "/v1/invoices/in_1D61oLDk7i9XGdoLVxklwJrU/lines"
  },
  "livemode": false,
  "metadata": {
  },
  "next_payment_attempt": null,
  "number": "EE2AACE-0001",
  "paid": true,
  "period_end": 1535918681,
  "period_start": 1535918681,
  "receipt_number": null,
  "starting_balance": 0,
  "statement_descriptor": null,
  "subscription": "sub_00000000000000",
  "subtotal": 0,
  "tax": null,
  "tax_percent": null,
  "total": 0,
  "webhooks_delivered_at": 1535918684
   }}}"

1 Ответ

0 голосов
/ 06 сентября 2018

Это сделает работу.

$input = file_get_contents('php://input');
$json = json_decode($input, TRUE);
$period_start = $json['data']['object']['lines']['data'][0]['period']['start'];
$period_end = $json['data']['object']['lines']['data'][0]['period']['end'];
echo $period_start; //1536177905
echo $period_end; //1536264305
...