PHP code example of komoju-official / komoju-sdk

1. Go to this page and download the library: Download komoju-official/komoju-sdk 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/ */

    

komoju-official / komoju-sdk example snippets



fig = Komoju\Configuration::getDefaultConfiguration()
    ->setApiKey('YOUR_SECRET_KEY');


$sessionsApi = new Komoju\Api\SessionsApi(new GuzzleHttp\Client(), $config);

$session = $sessionsApi->createSession(
    new Komoju\Model\CreateSessionRequestWithPaymentMode([
        'mode'       => 'payment',
        'amount'     => 1000,
        'currency'   => 'JPY',
        'return_url' => 'https://your-site.com/orders/return',
    ])
);

header('Location: ' . $session->getSessionUrl());


$sessionId = $_GET['session_id'];

$komojuSession = $sessionsApi->showSession($sessionId);

if ($komojuSession->getStatus() === Komoju\Model\SessionStatus::COMPLETED) {
    // payment status will be "captured", "authorized", or "pending"
    echo 'Payment ' . $komojuSession->getPayment()->getStatus();
} else {
    echo 'Payment was cancelled or failed';
}

try {
    $payment = $paymentsApi->showPayment('pay_xxx');
} catch (Komoju\ApiException $e) {
    echo $e->getCode();       // HTTP status code (e.g. 404, 422)
    echo $e->getMessage();    // Human-readable description
    print_r($e->getResponseBody()); // Full response body
}