1. Go to this page and download the library: Download soap/laravel-omise 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/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Soap\LaravelOmise\Omise;
use Soap\LaravelOmise\Omise\Charge;
use Soap\LaravelOmise\Omise\Error;
class PaymentController extends Controller
{
public function __construct(protected Omise $omise) {}
public function create()
{
$publicKey = $this->omise->getPublicKey();
return view('payments.form', compact('publicKey'));
}
}
$charge = app('omise')->charge()->find($id);
$charge->isPaid(); // is it paid?
$charge->isAwaitCapture(); // is it waiting for capture
$charge->isFailed(); // status == failed
$charge->getAmount(); // get unit amount in the based currency e.g. 100 THB
$charge->getRawAmount(); // get minor amount in based currency e.g. 10000 Satang (THB)
$charge->getMetadata('booking_id'); // get metadata you provide when create a charge
namespace App\Services;
use App\Contracts\PaymentProcessorInterface;
use Soap\LaravelOmise\Omise\Error;
class CreditCardPaymentProcessor implements PaymentProcessorInterface
{
/**
* Use token to authorize payment
*/
public function createPayment(float $amounnt, string $currency = 'THB', array $paymentDetails = []): array
{
$charge = app('omise')->charge()->create([
'amount' => $amounnt * 100,
'currency' => $currency,
'card' => $paymentDetails['token'],
'capture' => $paymentDetails['capture'] ?? true,
'webhook_endpoints' => $paymentDetails['webhook_endpoints'] ?? null,
'metadata' => $paymentDetails['metadata'] ?? [],
]);
if ($charge instanceof Error) {
return [
'code' => $charge->getCode(),
'error' => $charge->getMessage(),
];
}
return [
'charge_id' => $charge->id,
'amount' => $charge->amount / 100,
'currency' => $charge->currency,
'status' => $charge->status,
'paid' => $charge->paid,
'paid_at' => $charge->paid_at,
'charge' => $charge,
];
}
/**
* Process payment using charge id
*/
public function processPayment(array $paymentData): array
{
return [];
}
/**
* Refund payment using charge id
*/
public function refundPayment(string $chargeId, float $amount): bool
{
return true;
}
public function hasRefundSupport(): bool
{
return true;
}
public function isOffline(): bool
{
return false;
}
}