asaokamei/payjp

a simple wrapper for Pay.JP payments

0.0.2 2016-05-09 09:08 UTC

This package is auto-updated.

Last update: 2024-10-28 17:27:51 UTC


README

a simple wrapper classes for Pay.JP and WebPay payment services.

!!!NOT FULLY TESTED nor USED!!!

License

MIT License

PSR

PSR-1, PSR-2, and PSR-4.

install

composer require "asaokamei/payjp"

to see a demo, try

cd payjp
composer install
cd demo
php -S localhost:8888

and browse http://localhost:8888/.

Getting Started

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); 

charge to a credit card

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.

capture, cancel, or refund

$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.

Testing

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.

Notice

  • refund is not working for pay.jp.