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