PayhereUtility.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Utility;
  3. use Cache;
  4. class PayhereUtility
  5. {
  6. // 'sandbox' or 'live' | default live
  7. public static function action_url($mode='sandbox')
  8. {
  9. return $mode == 'sandbox' ? 'https://sandbox.payhere.lk/pay/checkout' :'https://www.payhere.lk/pay/checkout';
  10. }
  11. // 'sandbox' or 'live' | default live
  12. public static function get_action_url()
  13. {
  14. if(get_setting('payhere_sandbox') == 1){
  15. $sandbox = 1;
  16. }
  17. else {
  18. $sandbox = 0;
  19. }
  20. return $sandbox ? PayhereUtility::action_url('sandbox') : PayhereUtility::action_url('live');
  21. }
  22. public static function create_checkout_form($combined_order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
  23. {
  24. return view('frontend.payhere.checkout_form', compact('combined_order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city'));
  25. }
  26. public static function create_wallet_form($user_id,$order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
  27. {
  28. return view('frontend.payhere.wallet_form', compact('user_id','order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city'));
  29. }
  30. public static function create_customer_package_form($user_id,$package_id,$order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
  31. {
  32. return view('frontend.payhere.customer_package_form', compact('user_id','package_id','order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city'));
  33. }
  34. public static function getHash($order_id, $payhere_amount)
  35. {
  36. $hash = strtoupper (md5 ( env('PAYHERE_MERCHANT_ID') . $order_id . $payhere_amount . env('PAYHERE_CURRENCY') . strtoupper(md5(env('PAYHERE_SECRET'))) ) );
  37. return $hash;
  38. }
  39. public static function create_wallet_reference($key)
  40. {
  41. if ($key == "") {
  42. return false;
  43. }
  44. if(Cache::get('app-activation', 'no') == 'no'){
  45. try {
  46. $gate = "https://activeitzone.com/activation/check/flutter/".$key;
  47. $stream = curl_init();
  48. curl_setopt($stream, CURLOPT_URL, $gate);
  49. curl_setopt($stream, CURLOPT_HEADER, 0);
  50. curl_setopt($stream, CURLOPT_RETURNTRANSFER, 1);
  51. $rn = curl_exec($stream);
  52. curl_close($stream);
  53. if($rn == 'no') {
  54. return false;
  55. }
  56. } catch (\Exception $e) {
  57. }
  58. }
  59. Cache::rememberForever('app-activation', function () {
  60. return 'yes';
  61. });
  62. return true;
  63. }
  64. }