0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHP: stripe API 使い方 (List all customers)

Posted at

こちらのページの続きです。
stripe API 使い方 (List all customers)

#PHP Requests でカスタマーの一覧を取得#

必要なライブラリーのインストール

composer require rmccue/requests
composer require vlucas/phpdotenv

ツリー構造

$ tree -a -L 1
.
├── .env -> ../.env
├── composer.json
├── composer.lock
├── get_customers_requests.php
└── vendor
get_customers_requests.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
//	get_customers_requests.php
//
//					Dec/19/2021
// ------------------------------------------------------------------
require_once("vendor/autoload.php");
//
fputs (STDERR,"*** 開始 ***\n");

Requests::register_autoloader();

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$secret_key = $_ENV['SECRET_KEY'];

$url = 'https://api.stripe.com/v1/customers';

$headers = array('Accept' => 'application/json');
$options = array('auth' => array($secret_key, ''));

$request = WpOrg\Requests\Requests::get($url, $headers, $options);

var_dump($request->status_code);

$json_string = $request->body;

$dict_aa = json_decode ($json_string,true);

// var_dump ($dict_aa["data"]);

foreach ($dict_aa["data"] as $value)
	{
	print $value["id"] . "\n";
	}

fputs (STDERR,"*** 終了 ***\n");
// ------------------------------------------------------------------
?>

実行結果

$ ./get_customers_requests.php 
*** 開始 ***
PHP Deprecated:  The PSR-0 `Requests_...` class names in the Request library are deprecated. Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience. in /home/uchida/projects/stripe/php_requests/vendor/rmccue/requests/library/Requests.php on line 24
int(200)
cus_KmrIU4hzWqYt7R
cus_KmoG4k1wiKxSDc
cus_KmnqmJhBAvPGMq
cus_KmnpiRFjm8he97
*** 終了 ***

#PHP sdk でカスタマーの一覧を取得#

必要なライブラリーのインストール

composer require stripe/stripe-php
composer require vlucas/phpdotenv

ツリー構造

$ tree -a -L 1
.
├── .env -> ../.env
├── composer.json
├── composer.lock
├── get_customers_sdk.php
└── vendor
get_customers_sdk.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
//	get_customers_sdk.php
//
//					Dec/19/2021
// ------------------------------------------------------------------
require_once("vendor/autoload.php");
//
fputs (STDERR,"*** 開始 ***\n");

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$secret_key = $_ENV['SECRET_KEY'];

$stripe = new \Stripe\StripeClient($secret_key);

$cc = $stripe->customers->all(['limit' => 10]);

// var_dump ($cc["data"]);

foreach ($cc["data"] as $value)
	{
	print $value["id"] . "\n";
	}

fputs (STDERR,"*** 終了 ***\n");
// ------------------------------------------------------------------
?>

実行結果

$ ./get_customers_sdk.php 
*** 開始 ***
cus_KmrIU4hzWqYt7R
cus_KmoG4k1wiKxSDc
cus_KmnqmJhBAvPGMq
cus_KmnpiRFjm8he97
*** 終了 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?