LoginSignup
2
1

More than 5 years have passed since last update.

PAYJPの通信時にメンテナンスエラーをPHPで発生させるメモ

Posted at

メンテナンスがあるんですが、どうやったらPAYJPがメンテナンスの状態を再現できるかしらと思って試したメモ書き。

PHP ライブラリのバージョンは最新版を使っています。

HTTPClient が 503 を返すようにする

payjp.js の方はやり方が僕にはわからなかったのと、通信エラーの例外が出る事を確認したいので、PAYJPのHTTPクライアントをすり替える方法でやった。

Infrastructure/Payments/PayJP/Test/MaintenanceErrorClient.php
<?php
/**
 * Created by IntelliJ IDEA.
 * User: yasui
 * Date: 2017/01/23
 * Time: 19:39
 */

namespace Infrastructure\Payments\PayJP\Test;


use Payjp\HttpClient\ClientInterface;

/**
 * Class APIFailerResponse
 * @package App\Lib\Data\Payment\PayJP\Test
 *
 * メンテナンスエラーを常に出すHTTPクライアント
 */
class MaintenanceErrorClient implements ClientInterface
{
    public function request($method, $absUrl, $headers, $params, $hasFile)
    {
        $rdata =<<<__EOL__
{
    "error": {
        "code": "under_maintenance",
        "message": "PAY.JP is currently undergoing maintenance. Please try again later.",
        "status": 503,
        "type": "server_error"
    }
}
__EOL__;

        return [$rdata, 503];
    }

}

後はAPIKey を設定した直後あたりに、上記のクライアントを使うようにしてやれば良いです。

// API リクエスト
\Payjp\Payjp::setApiKey( \Config::get( 'payjp.key' ) );

// メンテナンスエラーを強制発生させる
\Payjp\ApiRequestor::setHttpClient( new \ Infrastructure\Payments\PayJP\Test\MaintenanceErrorClient() );

参考

PAYJP のライブラリが読みやすくてよかった :-)

see: http://payjp-announce.hatenablog.com/entry/2017/01/20/123520

2
1
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
2
1