| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace Webkul\Payment;
- use Illuminate\Support\Facades\Config;
- class Payment
- {
- /**
- * Returns all supported payment methods
- *
- * @return array
- */
- public function getSupportedPaymentMethods()
- {
- return [
- 'payment_methods' => $this->getPaymentMethods(),
- ];
- }
- /**
- * Returns all supported payment methods
- *
- * @return array
- */
- public function getPaymentMethods()
- {
- $paymentMethods = [];
- foreach (Config::get('payment_methods') as $paymentMethodConfig) {
- $paymentMethod = app($paymentMethodConfig['class']);
- if ($paymentMethod->isAvailable()) {
- $paymentMethods[] = [
- 'method' => $paymentMethod->getCode(),
- 'method_title' => $paymentMethod->getTitle(),
- 'description' => $paymentMethod->getDescription(),
- 'sort' => $paymentMethod->getSortOrder(),
- 'image' => $paymentMethod->getImage(),
- ];
- }
- }
- usort($paymentMethods, function ($a, $b) {
- if ($a['sort'] == $b['sort']) {
- return 0;
- }
- return ($a['sort'] < $b['sort']) ? -1 : 1;
- });
- return $paymentMethods;
- }
- /**
- * Returns payment redirect url if have any
- *
- * @param \Webkul\Checkout\Contracts\Cart $cart
- * @return string
- */
- public function getRedirectUrl($cart)
- {
- $payment = app(Config::get('payment_methods.'.$cart->payment->method.'.class'));
- return $payment->getRedirectUrl();
- }
- /**
- * Returns payment method additional information
- *
- * @param string $code
- * @return array
- */
- public static function getAdditionalDetails($code)
- {
- $paymentMethodClass = app(Config::get('payment_methods.'.$code.'.class'));
- return $paymentMethodClass->getAdditionalDetails();
- }
- }
|