<?php
public function pay(Request $request, $id)
{
$order = Order::where('user_id', $request->user()->id)->findOrFail($id);
$paymentMethod = $request->payment_method;
$payment = $order->payment()->create([
'method' => $paymentMethod,
'status' => 'payment_new',
// 'amount' => $order->amount,
]);
// https://omnipay.thephpleague.com/gateways/build-your-own/
// Merchant Site - The website or application that initiates the payment (магазит, сайт для создания заказа/плтежа)
// Merchant - The owner or operator of the Merchant Site (владелец сайта магазина)
// Payment Gateway - The remote payment processing system that handles the communication and transfer of funds between the Merchant Site (платежная система)
// Off-site gateways such as PayPal Express, where the customer is redirected to a third party site to enter payment details
// On-site (merchant-hosted) gateways such as PayPal Pro, where the customer enters their credit card details on your site
$params = [
'amount' => $order->amount,
'currency' => 'RUB',
'transactionId' => $order->number, // Is the Merchant’s reference to the transaction - so typically the ID of the payment record in the Merchant Site’s database
'description' => "Some description (order $order->number)",
'interface' => 'web',
// 'action' => 'payway',
// 'payway' => 'privat24_liqpay_merchant3_uah',
'returnUrl' => route('pay-successful-page', [$paymentMethod, 'order' => $order->id]), // перенаправление клиента после платежа
'returnMethod' => 'GET',
'cancelUrl' => route('pay-failed-page'), // перенаправление клиента после не успешного платежа
'cancelMethod' => 'GET',
'notifyUrl' => route('pay-successful-page'), // уведомление от Payment Gateway для Merchant Site о платеже
'notifyMethod' => 'POST',
// 'returnUrl' => "https://mydomain.com/payment/interkassa/success?order=$order->number",
// 'returnMethod' => 'GET',
// 'cancelUrl' => 'https://mydomain.com/payment/interkassa/cancel',
// 'cancelMethod' => 'GET',
// 'notifyUrl' => 'https://mydomain.com/payment/interkassa/notify',
// 'notifyMethod' => 'POST',
];
$response = \Omnipay::gateway($paymentMethod)->purchase($params)->send();
if ($response->isSuccessful()) {
dump('payment was successful: update database');
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
dump('redirect to offsite payment gateway');
// redirect to offsite payment gateway
return $response->getRedirectResponse();
} else {
dump('payment failed: display message to customer');
// payment failed: display message to customer
echo $response->getMessage();
}
}
- https://omnipay.thephpleague.com/
- https://github.com/thephpleague/omnipay
- https://github.com/thephpleague/omnipay-common/blob/master/src/Common/GatewayInterface.php
- https://github.com/thephpleague/omnipay-sagepay/blob/master/src/ServerGateway.php
- https://github.com/thephpleague/omnipay-sagepay
- https://groups.google.com/forum/#!forum/omnipay
Upgrade guide for omnipay/common https://github.com/thephpleague/omnipay-common/blob/master/UPGRADE.md
completeRegistration() = completePurchase() = completeAuthorize() is deprecated, use acceptNotification(array $parameters = [])
if ($gateway->supportsAcceptNotification()) { //supportsCompletePurchase, supportsPurchase, supportsCompleteAuthorize,...
\Log::info('support AcceptNotification');
}
completePurchase() - когда пользователь возвращается с плаетжки на страницу магазина
acceptNotification() - когда платежка возвращает результат платежа в магазин
// authorize($options) - authorize an amount on the customer's card
// completeAuthorize($options) - handle return from off-site gateways after authorization
// capture($options) - capture an amount you have previously authorized
// purchase($options) - authorize and immediately capture an amount on the customer's card
// completePurchase($options) - handle return from off-site gateways after purchase
// refund($options) - refund an already processed transaction
// void($options) - generally can only be called up to 24 hours after submitting a transaction
// acceptNotification() - convert an incoming request from an off-site gateway to a generic notification object for further processing
public function completeRegistration(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\ServerTokenRegistrationCompleteRequest', $parameters);
}
public function completeAuthorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\ServerCompleteAuthorizeRequest', $parameters);
}
public function completePurchase(array $parameters = array())
{
return $this->completeAuthorize($parameters);
}
public function acceptNotification(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\ServerNotifyRequest', $parameters);
}
$gateway = \Omnipay::gateway($gateway);
$response = $gateway->acceptNotification($request->all())->send();
$response->getTransactionId(); // the reference set by the originating website if available.
$response->getTransactionReference(); // A reference provided by the gateway to represent this transaction
$response->getTransactionStatus(); // Current status of the transaction, one of NotificationInterface::STATUS_*
$response->getMessage(); // Additional message, if any, provided by the gateway
$response->isSuccessful(); // is the response successful?
$response->isRedirect(); // is the response a redirect?
// update the status of the corresponding transaction in your database