Project provides abstract implementation for payment providers:
- paypal (classic API, REST API)
- paymill (credit cards, sepa, paypal)
- icepay (credit cards, bancontact, eps, giropay, ideal, sofort)
- braintree
- axcess
- valu
- proforma / upn
Currently waiting for implementation:
- paywiser
- activa
- megapos
You can install package via composer.
$ composer require schtr4jh/payment'enabled' => true,
'private_key' => env('PAYMILL_PRIVATE_KEY'),
'public_key' => env('PAYMILL_PUBLIC_KEY'),'enabled' => true,
'private_key' => env('PAYMILL_PRIVATE_KEY'),
'public_key' => env('PAYMILL_PUBLIC_KEY'),
'url_return' => 'payment.success',
'url_cancel' => 'payment.error','enabled' => true,
'private_key' => env('PAYMILL_PRIVATE_KEY'),
'public_key' => env('PAYMILL_PUBLIC_KEY'),'enabled' => true,
'username' => 'schtr4jh-facilitator_api1.schtr4jh.net',
'password' => '1390585136',
'signature' => 'AOZR6pqlRlwo0Ex9.oQbP2uvOalsAHQdlhdfczB0.B699lqJXv8pigFj',
'url' => 'https://api-3t.sandbox.paypal.com/nvp',
'url_token' => 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=[token]',
'url_return' => 'payment.success',
'url_cancel' => 'payment.error','enabled' => false,
'id' => 'AYlzupNqmg7177ZI57MfI26mgkzN-n8QQewuicaHmi7OOEf5LNy5FIi7ooFIbwo-t9_LQR9NOqtLslF_',
'secret' => 'ECQLZ6zyH8b6JgG3hGN8Qg1u6ezDiT0HpfCK7MnKcQyyQoYtghnAndYJLu5p1g0UJmLMj7_IV1Qdbsv3',
'mode' => 'sandbox',
'url_return' => 'payment.success',
'url_cancel' => 'payment.error',
'log' => [
'enabled' => true,
'level' => 'DEBUG', // 'FINE' for production
],'enabled' => false,
'url_waiting' => 'payment.waiting',Each project needs to have implemented \Pckg\Payment\Adapter\Order|Product|Customer|Log|Environment (called ProjectOrder, ProjectProduct, ProjectCustomer and ProductLog) which provides proper mappers. For usage in Laravel project you can simply use Pckg\Payment\Service\LaravelPayment trait which creates payment service with Laravel environment for handling request, responses, url generation and redirects. For usage in other project simply implement Payment\Adapter\Environment.
// list payments'payment' => route('PaymentController@payment', 'payment/{listing}', 'GET'),
// apply promo code'payment.promo' => route('PaymentController@promo', 'payment/{handler}/{listing}/promo', 'POST'),
// validate payment request'payment.validate' => route('PaymentController@validate', 'payment/{handler}/{listing}/validate', 'POST'),
// start payment process'payment.start' => route('PaymentController@start', 'payment/{handler}/{listing}/start', 'POST|GET'),
// payment valid'payment.success' => route('PaymentController@success', 'payment/{handler}/{listing}/success', 'GET'),
// payment invalid'payment.error' => route('PaymentController@error', 'payment/{handler}/{listing}/error', 'GET'),
// payment not processed yet'payment.waiting' => route('PaymentController@waiting', 'payment/{handler}/{listing}/waiting', 'GET'),Example of full Laravel implementation
<?phpnamespaceNet\Http;
useIlluminate\Http\Request;
useNet\Http\Payment\ZoneLog;
useNet\Http\Payment\ZoneOrder;
useNet\Http\Requests\PromoCodeRequest;
usePckg\Payment\Service\LaravelPayment;
useZone\Content\SelectItem;
useZone\Listing\Listing;
useZone\Listing\PaymentMethod;
useZone\Listing\PromoCode;
class PaymentController extends BaseController
{
use LaravelPayment;
protected$paymentService;
publicfunction__construct()
{
$this->paymentService = $this->createPaymentService();
}
privatefunctionpreparePaymentService($handler, Listing$listing)
{
$listing->abortIfNotMine();
$this->paymentService->prepare(newZoneOrder($listing), $handler, newZoneLog($listing));
}
publicfunctiongetPayment(Listing$listing)
{
$listing->abortIfNotMine();
$this->paymentService->setOrder(newZoneOrder($listing));
$this->vendorAsset('schtr4jh/payment/src/Pckg/Payment/public/payment.js', 'footer');
returnview('payment.index', [
'listing' => $listing,
'paymentMethods' => PaymentMethod::where('enabled', 1)->get(),
'paymentService' => $this->paymentService,
'expYears' => range(date('Y') + 0, date('Y') + 16),
'expMonths' => SelectItem::cardExpirationMonths()->get(),
]);
}
publicfunctionpostStart($handler, Listing$listing)
{
$this->preparePaymentService($handler, $listing);
$success = $this->paymentService->getHandler()->start();
return [
'success' => true,
'modal' => $success
? '#dialog-payment-success'
: '#dialog-payment-error',
];
}
publicfunctiongetStart($handler, Listing$listing)
{
return$this->getStatus($handler, $listing, 'start');
}
publicfunctiongetSuccess($handler, Listing$listing)
{
return$this->getStatus($handler, $listing, 'success');
}
publicfunctiongetError($handler, Listing$listing)
{
return$this->getStatus($handler, $listing, 'error');
}
publicfunctiongetWaiting($handler, Listing$listing)
{
return$this->getStatus($handler, $listing, 'waiting');
}
publicfunctionpostValidate($handler, Listing$listing, Request$request)
{
$this->preparePaymentService($handler, $listing);
return$this->paymentService->getHandler()->validate($request);
}
publicfunctionpostPromo($handler, Listing$listing, PromoCodeRequest$request)
{
$this->preparePaymentService($handler, $listing);
$canApply = false;
$code = PromoCode::where('code', $request->promo_code)->first();
if ($code && (($code->discount_value && $code->discount_value < $this->paymentService->getTotal()) || $code->discount_percentage)) {
$listing->forceFill([
'promo_code_id' => $code->id,
])->save();
$canApply = true;
} else {
$listing->forceFill([
'promo_code_id' => null,
])->save();
}
return [
'success' => true,
'promo_notice' => $request->promo_code
? ($canApply
? trans(
'payment.label.promo_code_valid',
['discount' => $listing->promoCode->getDiscount($this->paymentService->getCurrency())]
) : trans('payment.label.promo_code_invalid')
) : '',
'new_handler_price' => $this->paymentService->getHandler()->getTotalToPay(),
'new_button' => trans('payment.paymill.btn.pay') . '' . $this->paymentService->getTotalToPayWithCurrency(),
];
}
protectedfunctiongetStatus($handler, Listing$listing, $action)
{
$this->preparePaymentService($handler, $listing);
$this->paymentService->getHandler()->{$action}();
returnview('payment.' . $action, [
'listing' => $listing,
]);
}
}