Payment.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Webkul\Payment;
  3. use Illuminate\Support\Facades\Config;
  4. class Payment
  5. {
  6. /**
  7. * Returns all supported payment methods
  8. *
  9. * @return array
  10. */
  11. public function getSupportedPaymentMethods()
  12. {
  13. return [
  14. 'payment_methods' => $this->getPaymentMethods(),
  15. ];
  16. }
  17. /**
  18. * Returns all supported payment methods
  19. *
  20. * @return array
  21. */
  22. public function getPaymentMethods()
  23. {
  24. $paymentMethods = [];
  25. foreach (Config::get('payment_methods') as $paymentMethodConfig) {
  26. $paymentMethod = app($paymentMethodConfig['class']);
  27. if ($paymentMethod->isAvailable()) {
  28. $paymentMethods[] = [
  29. 'method' => $paymentMethod->getCode(),
  30. 'method_title' => $paymentMethod->getTitle(),
  31. 'description' => $paymentMethod->getDescription(),
  32. 'sort' => $paymentMethod->getSortOrder(),
  33. 'image' => $paymentMethod->getImage(),
  34. ];
  35. }
  36. }
  37. usort($paymentMethods, function ($a, $b) {
  38. if ($a['sort'] == $b['sort']) {
  39. return 0;
  40. }
  41. return ($a['sort'] < $b['sort']) ? -1 : 1;
  42. });
  43. return $paymentMethods;
  44. }
  45. /**
  46. * Returns payment redirect url if have any
  47. *
  48. * @param \Webkul\Checkout\Contracts\Cart $cart
  49. * @return string
  50. */
  51. public function getRedirectUrl($cart)
  52. {
  53. $payment = app(Config::get('payment_methods.'.$cart->payment->method.'.class'));
  54. return $payment->getRedirectUrl();
  55. }
  56. /**
  57. * Returns payment method additional information
  58. *
  59. * @param string $code
  60. * @return array
  61. */
  62. public static function getAdditionalDetails($code)
  63. {
  64. $paymentMethodClass = app(Config::get('payment_methods.'.$code.'.class'));
  65. return $paymentMethodClass->getAdditionalDetails();
  66. }
  67. }