1. Go to this page and download the library: Download asciisd/cashier-core 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 Asciisd\CashierCore\Models\PaymentMethod;
// Create a payment method
$paymentMethod = PaymentMethod::create([
'user_type' => 'App\\Models\\User',
'user_id' => $user->id,
'processor_name' => 'stripe',
'processor_payment_method_id' => 'pm_1234567890',
'type' => 'credit_card',
'brand' => 'visa',
'last_four' => '4242',
'exp_month' => 12,
'exp_year' => 2025,
'is_default' => true,
]);
// Make it the default
$paymentMethod->makeDefault();
// Check expiration
if ($paymentMethod->is_expired) {
// Handle expired payment method
}
use Asciisd\CashierCore\Abstracts\AbstractPaymentProcessor;
use Asciisd\CashierCore\DataObjects\PaymentResult;
use Asciisd\CashierCore\DataObjects\RefundResult;
class CustomProcessor extends AbstractPaymentProcessor
{
protected array $supportedFeatures = ['charge', 'refund'];
public function getName(): string
{
return 'custom';
}
public function charge(array $data): PaymentResult
{
$validatedData = $this->validatePaymentData($data);
// Your payment processing logic here
return $this->createSuccessResult(
transactionId: 'custom_' . uniqid(),
amount: $validatedData['amount'],
currency: $validatedData['currency']
);
}
public function refund(string $transactionId, ?int $amount = null): RefundResult
{
// Your refund logic here
}
}