Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add service provider #36

Open
khunemz opened this issue Jul 22, 2016 · 13 comments
Open

How can I add service provider #36

khunemz opened this issue Jul 22, 2016 · 13 comments

Comments

@khunemz
Copy link

khunemz commented Jul 22, 2016

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.

@ghost
Copy link

ghost commented Jul 22, 2016

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.

@thanapongp
Copy link

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!

@khunemz
Copy link
Author

khunemz commented Jul 26, 2016

@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

@thanapongp
Copy link

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

@khunemz
Copy link
Author

khunemz commented Jul 29, 2016

@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')

@jrmadsen67
Copy link

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

@guzzilar
Copy link
Contributor

@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 #47

Cheers,
Nam

@eNzyOfficial
Copy link

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

@hanachan1026
Copy link

Is this moving forward?

@eNzyOfficial
Copy link

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

@thanapongp
Copy link

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

@eNzyOfficial
Copy link

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.

@ptucky
Copy link

ptucky commented Jan 26, 2020

charge

Great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants