a simple wrapper classes for Pay.JP and WebPay payment services.
!!!NOT FULLY TESTED nor USED!!!
MIT License
PSR-1, PSR-2, and PSR-4.
composer require "asaokamei/payjp"
to see a demo, try
cd payjp
composer install
cd demo
php -S localhost:8888
and browse http://localhost:8888/
.
Get public and secret api keys from Pay.jp or WebPay.jp.
define('PAY_JP_SECRET_KEY', 'sk_test_*****'); // your secret key.
Then, create a factory for charges, as
// for Pay.jp
$factory = AsaoKamei\PayJp\PayJp\ChargeFactory::forge(PAY_JP_SECRET_KEY);
// for WebPay.jp
$factory = AsaoKamei\PayJp\WebPay\ChargeFactory::forge(PAY_JP_SECRET_KEY);
get a credit token ($_POST['payjp-token']
for pay.jp or
$_POST['webpay-token']
for WebPay.jp).
$charge = $factory->create($_POST['service-token']);
if (!$charge_id = $charge->charge(1000)) {
var_dump($charge->getError());
}
You can authorize the credit, by,
$charge_id = $charge->authorize(1000);
and save the $charge_id
for later use.
$charge = $factory->retrieve($charge_id);
then, do one of the following.
$charge->capture();
$charge->cancel();
$charge->refund(500);
You can only refund once for pay.jp
.
To run the test, please obtain api keys for test from Pay.jp
and WebPay
.
Set the secret and public api keys to tests/services.ini
accordingly.
Then, run phpunit using tests/phpunit.xml
configuration.
refund
is not working for pay.jp.