1. Go to this page and download the library: Download aliff/chip-in 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/ */
aliff / chip-in example snippets
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
class PaymentController extends Controller
{
public function handleChipInCallback(Request $request)
{
$data = $request->all();
Log::info('💳 CHIP callback received', ['data' => $data]);
// ✅ Extract Entity ID (stored in reference)
$entityId = Arr::get($data, 'reference');
// Fallback: try metadata
if (! $entityId) {
$metadata = Arr::get($data, 'metadata', []);
$entityId = $metadata['entity_id'] ?? null;
}
if (! $entityId) {
Log::warning('⚠️ Missing Entity ID in callback', ['data' => $data]);
return response()->json(['error' => 'Missing Entity ID'], 400);
}
// ✅ Find your entity record (e.g., WillWasiat, Order, etc.)
$entity = YourModel::find($entityId);
if (! $entity) {
Log::warning("⚠️ Entity not found for ID {$entityId}");
return response()->json(['error' => 'Entity not found'], 404);
}
// ✅ Create or update Payment record
$payment = Payment::updateOrCreate(
['chip_id' => Arr::get($data, 'id')],
[
'payable_id' => $entity->id,
'payable_type' => YourModel::class,
'status' => Arr::get($data, 'status'),
'email' => Arr::get($data, 'email', Arr::get($data, 'client.email')),
'amount' => Arr::get($data, 'payment.amount', Arr::get($data, 'amount')),
'currency' => Arr::get($data, 'payment.currency', 'MYR'),
'reference' => Arr::get($data, 'reference'),
'brand_id' => Arr::get($data, 'brand_id'),
'payload' => $data,
'checkout_url' => Arr::get($data, 'checkout_url'),
'paid_at' => now(),
]
);
// ✅ Update entity status
$entity->update([
'payment_status' => $payment->status ?? 'pending',
]);
Log::info("✅ Payment stored & linked", [
'payment_id' => $payment->id,
'entity_id' => $entity->id,
'status' => $payment->status,
]);
// ✅ If callback came from browser (user flow), redirect back to app
if ($request->expectsJson() === false) {
return redirect()
->route('entity.completed', ['id' => $entity->id])
->with('success', 'Your payment has been successfully processed!');
}
// ✅ For API/callback endpoint
return response()->json(['success' => true]);
}
}
namespace App\Http\Controllers;
use Aliff\ChipIn\Http\Client;
use Aliff\ChipIn\Http\Endpoints\Purchase;
use Illuminate\Support\Facades\Crypt;
class OrderController extends Controller
{
public function proceed()
{
$payload = [
'client' => [
'email' => $this->entity->user->email ?? auth()->user()->email,
],
'purchase' => [
'products' => [
[
'name' => 'Your Product Name',
'price' => 13424, // Amount in cents (134.24)
'quantity' => 1,
],
],
'due_strict' => false,
],
'reference' => $this->entity->id, // ← Store your entity ID here
'success_redirect' => route('entity.completed', [
'id' => Crypt::encrypt($this->entity->id),
'status' => 'success'
]),
'failed_redirect' => route('entity.completed', [
'id' => Crypt::encrypt($this->entity->id),
'status' => 'failed'
]),
];
$purchase = new Purchase(app(Client::class));
return $purchase->createAndRedirect($payload);
}
}