PHP code example of asaokamei / payjp

1. Go to this page and download the library: Download asaokamei/payjp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asaokamei / payjp example snippets


define('PAY_JP_SECRET_KEY', 'sk_test_*****'); // your secret key.

// 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  = $factory->create($_POST['service-token']);

if (!$charge_id = $charge->charge(1000)) {
    var_dump($charge->getError());
}

$charge_id = $charge->authorize(1000);

$charge = $factory->retrieve($charge_id);

$charge->capture();
$charge->cancel();
$charge->refund(500);