PHP code example of yousefkadah / laravel-pelecard
1. Go to this page and download the library: Download yousefkadah/laravel-pelecard 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/ */
// Pass the token saved from the authorization response
Pelecard::capture($token, 5000);
$user->refund($transactionId, 5000);
use Yousefkadah\Pelecard\DTO\ChargeRequestDTO;
use Yousefkadah\Pelecard\DTO\AuthorizeRequestDTO;
### Custom Parameters (ParamX & ParamZ)
Pelecard supports custom parameters that are returned in callbacks and webhooks for tracking:
#### API Calls (ParamX & ParamZ)
Both ParamX and ParamZ are supported in direct API calls:
// Use saved token with 3DS authentication
$response = Pelecard::initiate3DS([
'amount' => 10000,
'currency' => 'ILS',
'token' => $user->pelecard_token,
]);
// Redirect user to 3DS authentication page
$redirectUrl = $response->get('RedirectUrl');
return redirect($redirectUrl);
// Update expiry date when card is renewed
Pelecard::updateToken($user->pelecard_token, [
'expiry_month' => '01',
'expiry_year' => '2026',
]);
// Get complete transaction data
$transactions = Pelecard::getCompleteTransData([
'from_date' => '2025-01-01',
'to_date' => '2025-01-31',
]);
// Get specific transaction
$transaction = Pelecard::getTransaction($uniqueId);
use Yousefkadah\Pelecard\Helpers\InvoiceBuilder;
$invoice = (new InvoiceBuilder())
->number('INV-2025-001')
->date(now())
->dueDate(now()->addDays(30))
->vendor([
'name' => 'Your Company',
'address' => '123 Main St, City',
'phone' => '+972-50-1234567',
'email' => '[email protected]',
])
->customer([
'name' => $user->name,
'email' => $user->email,
'address' => $user->address,
])
->addItem('Premium Subscription', 1, 10000)
->addItem('Setup Fee', 1, 5000)
->taxRate(17) // 17% VAT
->notes('Thank you for your business!')
->terms('Payment due within 30 days')
->currency('ILS')
->build();
// Render as HTML
$html = $invoice->render();
// Or use the builder directly
$html = (new InvoiceBuilder())
->number('INV-001')
->customer(['name' => 'John Doe'])
->addItem('Service', 1, 10000)
->render();
$html = (new InvoiceBuilder())
->template('invoices.custom') // Use your custom template
->number('INV-001')
->build()
->render();
// Get error message in Hebrew
$errorMessage = Pelecard::getErrorMessageHe('001');
// Get error message in English
$errorMessage = Pelecard::getErrorMessageEn('001');
// Auto-detect language from config
$errorMessage = Pelecard::getErrorMessage('001');
// Single price
$user->newSubscription('default', 'price_monthly')
->trialDays(14)
->create($paymentMethod);
// Multiple prices (stored in subscription_items)
$user->newSubscription('default', ['price_seat', 'price_addon'])
->quantity(3, 'price_seat')
->create($paymentMethod);
if ($user->subscribed('default')) {
// User has a valid subscription (active, on trial, or on grace period)
}
// Subscribed to a specific price or product
$user->subscribed('default', 'price_monthly');
$user->subscribedToPrice('price_monthly', 'default');
$user->subscribedToProduct('prod_premium', 'default');
if ($user->onTrial('default')) {
// User is on trial
}
// Payment state
$user->hasIncompletePayment('default');
$subscription = $user->subscription('default');
$subscription->active();
$subscription->canceled();
$subscription->onGracePeriod();
$subscription->ended();
$subscription->pastDue();
// Cancel at end of billing period (enters grace period)
$user->subscription('default')->cancel();
// Cancel immediately
$user->subscription('default')->cancelNow();
// Cancel at a specific time
$user->subscription('default')->cancelAt(now()->addDays(10));
$user->subscription('default')->resume();
// Swap to a single price
$user->subscription('default')->swap('price_yearly');
// Swap to multiple prices
$user->subscription('default')->swap(['price_yearly', 'price_addon']);
// Team model
use Yousefkadah\Pelecard\Concerns\ManagesPelecardCredentials;
class Team extends Model
{
use ManagesPelecardCredentials;
}
// Setup team credentials
$team->createPelecardCredentials(
terminal: '1234567',
user: 'api_user',
password: 'api_password'
);
// User model
class User extends Model
{
use Billable;
public function pelecardCredentials()
{
return $this->team->pelecardCredentials;
}
}
// Usage - automatically uses team's credentials
$user->charge(10000, 'Payment');
// Create client for specific tenant
$client = PelecardClient::for($user);
$client = PelecardClient::for($team);
// Use client
$response = $client->charge([
'amount' => 10000,
'currency' => 'ILS',
'token' => 'payment_token',
]);
use Yousefkadah\Pelecard\Events\PaymentSucceeded;
use Yousefkadah\Pelecard\Events\PaymentFailed;
// In EventServiceProvider
protected $listen = [
PaymentSucceeded::class => [
SendPaymentConfirmation::class,
],
PaymentFailed::class => [
NotifyPaymentFailure::class,
],
];
if ($user->hasDefaultPaymentMethod()) {
// User has a payment method on file
}
// Get all transactions for a user
$transactions = $user->pelecardTransactions;
// Get successful transactions
$successful = $user->pelecardTransactions()->successful()->get();
// Get transactions of specific type
$charges = $user->pelecardTransactions()->ofType('charge')->get();