omise-php icon indicating copy to clipboard operation
omise-php copied to clipboard

How can I add service provider

Open khunemz opened this issue 8 years ago • 13 comments

I am working on Laravel project . It throw error about the dash sign on file name 'omise-php' . How can I fix it ??

in the UsersController , you can notice that it hit the line number 6 and thrown error.

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use omise\omise-php\lib\Omise;

class UsersController extends Controller
{
 // ... others actions
}

in the app.php

 // .. other service providers
  Laravel\Cashier\CashierServiceProvider::class,
  omise\omise-php\lib\Omise::class,
 // .. other service providers

Error that was thrown screen shot 2016-07-26 at 20 58 08

Moreover, in naming convention , I have never seen name with dash sign before . I have seen only camelCase , snake_case or PascalCase.

khunemz avatar Jul 22 '16 15:07 khunemz

hello @khunemz

thank you for using Omise, can you give me more detail such as

  • what error have you found ?
  • some part of your code ?

so I can investigate your problem and give an exactly advise for you.

ghost avatar Jul 22 '16 16:07 ghost

Hi, I also working on Laravel project using this library as well but, I don't use service provider to make this library work with laravel, instead I use this very quick and dirty way.

(I have a bad English skill, so bare with me)

  1. Create new folder inside 'app' directory and name it however you want.
  2. Put 'data', 'lib' and 'tests' folder from library in that folder.
  3. Create a new class and set the namespace appropriately. (Eg. App\Cashier)
  4. Manually include 'lib/Omise.php' into your class file, so it should look something like this.
namespace App\Services;

require_once dirname(__FILE__, 3).'/app/Omise/lib/Omise.php';

class Cashier
{
}

And just call Omise's methods inside that class like this.

namespace App\Services;

require_once dirname(__FILE__, 3).'/app/Omise/lib/Omise.php';

class Cashier
{

    public static function charge(Array $data)
    {
        return \OmiseCharge::create($data);
    }

}

Now you can use your class as an interface (not sure what to call it) to communicate with Omise from anywhere in your Laravel app. For example :

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Services\Cashier;

class User extends Authenticatable
{

     /**
     * Charge the customer.
     *
     * @param  integer  $amount
     * @param  string  $card
     * @return OmiseChargeObject
     */
    public function charge($amount, $card)
    {
        return Cashier::charge([
            'amount' => $amount,
            'currency' => 'thb',
            'customer' => $this->customerToken,
            'card' => $card,
        ]);
    }

}

And that's it.

Keep in mind that this is very quick and dirty way to do it. If you happen to find a better way, please share!

thanapongp avatar Jul 22 '16 16:07 thanapongp

@supershooter152 useful idea , i ll try it. (could I add the 'lib' folder into autoload psr-4 ?)

@bank-omise I challenge you if you make Omise and Laravel (the world's most popular PHP framework) integrating more easily , you would solve an annoying problem in the world

khunemz avatar Jul 26 '16 14:07 khunemz

Haven't got around to try it yet, but my guess is that you could.

thanapongp avatar Jul 27 '16 17:07 thanapongp

@supershooter152 nope , it does not work . Instead it shows .

[Symfony\Component\Debug\Exception\FatalErrorException]
  main(): Failed opening required '/Users/xxxxxxx/project/app/Omise/lib/Omise.php'
   (include_path='.:/usr/local/php5/lib/php')

khunemz avatar Jul 29 '16 13:07 khunemz

this is really quite ridiculous that you don't even namespace. you make a simple thing a big pain :-(

jrmadsen67 avatar Jan 24 '17 02:01 jrmadsen67

@jrmadsen67 Hi,

I understand. Now we are working on new version of Omise-PHP that would support namespace feature. You could follow the project here: https://github.com/omise/omise-php/projects/1#card-963281

Also, for the adding namespace PR, now it's in review process, which is you can follow the PR at https://github.com/omise/omise-php/pull/47

Cheers, Nam

guzzilar avatar Jan 24 '17 03:01 guzzilar

It's been 2 years and you guys still haven't namespaced this? Is this ever going to happen?

eNzyOfficial avatar Aug 09 '18 08:08 eNzyOfficial

Is this moving forward?

hanachan1026 avatar Sep 18 '19 09:09 hanachan1026

don't hold your breathe, I've been asking for namespaces for about 16 months now

eNzyOfficial avatar Sep 24 '19 05:09 eNzyOfficial

We might as well fork this and add proper namespace ourselve now lol.

thanapongp avatar Sep 24 '19 05:09 thanapongp

It would seem like the best thing to do, people have been asking for namespaces for like 3-4 years now, let alone other basic features. Seems weird that a first party package can be so outdated and unmaintained. We gave up in the end and used another payment gateway.

eNzyOfficial avatar Sep 25 '19 09:09 eNzyOfficial

charge

Great

ptucky avatar Jan 26 '20 08:01 ptucky