PHP code example of premmohantyagi / apihub-laravel
1. Go to this page and download the library: Download premmohantyagi/apihub-laravel 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/ */
use ApiHub\Laravel\Facades\Email;
Email::send($message); // uses the configured default driver
Email::driver('resend')->send($m); // uses a specific driver
$result = Email::send($message);
$result->accepted(); // bool
$result->id(); // provider message id
$result->response?->raw(); // the underlying Laravel HTTP response
$result->response?->json('some.provider.specific.field');
use ApiHub\Laravel\Exceptions\ApiHubException;
use ApiHub\Laravel\Exceptions\AuthenticationException;
use ApiHub\Laravel\Exceptions\RateLimitException;
try {
Ai::chat($request);
} catch (AuthenticationException $e) { // 401 / 403
// bad or missing credentials
} catch (RateLimitException $e) { // 429
// back off and retry later
} catch (ApiHubException $e) { // any other 4xx / 5xx
report($e);
$e->statusCode; // HTTP status
$e->driver; // which driver failed
$e->response; // the ApiHub Response (->raw(), ->json(), ->status())
}
$fake = Email::fake();
// ...code under test calls Email::send(...)...
$fake->assertSent(fn ($message) => $message->subject === 'Welcome');
$fake->assertSentCount(1);
use ApiHub\Laravel\Facades\Email;
use ApiHub\Laravel\Email\DTO\EmailMessage;
use ApiHub\Laravel\Email\DTO\Attachment;
$message = EmailMessage::make()
->from('[email protected]', 'Acme')
->to('[email protected]') // string, or an array of addresses
->cc(['[email protected]'])
->bcc('[email protected]')
->replyTo('[email protected]', 'Support')
->subject('Welcome')
->html('<p>Hello!</p>')
->text('Hello!') // optional plain-text part
->header('X-Campaign', 'welcome')
->attach(Attachment::fromPath(storage_path('invoice.pdf')));
$result = Email::send($message);
$result->accepted(); // bool
$result->id(); // provider message id
// Webhook mode:
Sms::driver('discord')->send(TextMessage::make()->text('Build passed'));
// Bot mode, to a channel id:
Sms::driver('discord')->send(TextMessage::make()->to('123456789012345678')->text('Hi'));
use ApiHub\Laravel\Facades\Payments;
use ApiHub\Laravel\Payments\DTO\ChargeRequest;
use ApiHub\Laravel\Payments\DTO\RefundRequest;
$charge = Payments::charge(
ChargeRequest::make()
->amount(1050, 'USD') // 1050 = $10.50, held in the currency's minor units
->source('pm_card_visa') // gateway token / nonce / payment method
->customer('cus_123') // optional
->description('Order #42')
->reference('order-42') // used as the idempotency key where supported
->metadata(['order_id' => '42'])
);
$charge->successful(); // bool
$charge->id(); // gateway id (payment intent / order / payment / transaction)
$charge->status();
$refund = Payments::refund(
RefundRequest::make()
->payment($charge->id())
->amount(500, 'USD') // omit for a full refund
->reason('requested_by_customer')
);
$order = Payments::driver('razorpay')->charge(
ChargeRequest::make()->amount(50000, 'INR')->reference('rcpt-1')
);
// $order->id() returns "order_...", pass it to Razorpay Checkout on the client.
use ApiHub\Laravel\Facades\Payments;
public function handle(Request $request)
{
$valid = Payments::driver('stripe')->verifyWebhook(
$request->getContent(), // the raw body
$request->headers->all(), // all request headers
);
abort_unless($valid, 400);
// ...handle the verified event...
}