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

Add new payment method #110

Open
ramoncodit opened this issue Nov 7, 2018 · 12 comments
Open

Add new payment method #110

ramoncodit opened this issue Nov 7, 2018 · 12 comments

Comments

@ramoncodit
Copy link

Good evening,
I'm looking for to add a new Payment method.
As far as I could see, Goteo platform is using Omnipay lib, who allows to interact with a wide variety of payment platforms, with Paypal among that.

In config/settings.yml I can see payment gateway settings, by default paypal:

# Payment methods, must be registered as classes implementing Goteo\Payment\Method\PaymentMethodInterface
payments:
    # Paypal
    paypal:
        active: true
        testMode:  true # set to false to real checkouts
        username: paypal@example.com
        password: paypal-password
        signature: PAYPAL-Signature
        appId: PAYPAL-APP-ID

As it can be read, there's a comment line where appoints to add new payment form:

# Additional custom payment methods should be added here

I have checked that Omnipay allows Stripe gateway and has its methods into vendor/omnipay folder.
So, I tried to add Stripe payment method. Here are my steps:

  1. Added code block on config/settings.yml, let's say:
    stripe:
        active: true
        testMode:  true # set to false to real checkouts
        username: stripe@example.com
        password: stripe-password
        signature: STRIPE-Signature
        appId: STRIPE-APP-ID

In order to continue, I realised that all payment steps are controlled into :

  • src/Goteo/Controller/InvestController.php

In other hand, I found a PayPal library file on:

  • src/Goteo/Library/Paypal.php

And a "Payment lib" who works as a payment library methods, I suppose...

  • src/Goteo/Payment/Payment.php

I suppose I must implement de Stripe library, something as create a file like follows:

  • src/Goteo/Library/Stripe.php
    to implement specific methods to interact with Stripe API.
    And this other one too:
  • src/Goteo/Payment/Method/StripePaymentMethod.php

But what worries me is that I have seen that in project config, in step 6, appears a check to allow to pay it with paypal method. That option is saved into database table project_account, with specific fields: 'paypal' & 'paypal_owner', next to fields 'bank' & 'bank_owner'
So, my question is, to add Stripe payment method, it has to been added new fields like 'stripe' & 'stripe_owner' in that table ?
In that way, to add new payment method, means that are straight "hard-linked" to project definition ?

Or maybe I'm complicating the matter more than I should... ?

Thanks in advance for to have read till here.
Greetings

@microstudi
Copy link
Contributor

Hi, I'm happy that someone is going to implement a new Payment Method.

First, forget about the Library/Paypal.php file, that's used in the legacy system and we didn't remove it yet because i may break things with the old admin.

The key is to implement Goteo\Payment\Method\PaymentMethodInterface interface and register the class as is done in the Config.php file. After that, it can be included in the settings file.

In the core code we have 3 payment implementations Cash, Paypal and Pool.

There's a 4th implementation in the Goteo-Dev plugin that registers itself if you activate the plugin in its start.php file.

if you study these cases you shouldn't have problems to implement a new Payment method. And I don't think you'll need to create any Library/Stripe.php additional class, adding the Omnipay Stripe class in composer.json omnipay/stripe should be enough.

Check the documentation of Omnipay regarding Stripe.

About the paypal fields: There are not related to the payment, all the payment info is in the invest table, those fields are for the project owners (we require them to have a paypal account if they want to accept and receive money that way). So, don't bother about them.

Feel free to start coding and show me your progress, I'll give you my comments, but please use the latests versions of the Goteo source code.

Good luck!

@ramoncodit
Copy link
Author

Hi!
first of all, thanks in advance for your quick response!
I'll start working as you have suggested me.

Thanks!

@ramoncodit
Copy link
Author

Hi @microstudi ,
to start with new payment method, I've thought maybe it's better to focus it as a plugin, like dummy payment method.
So I've followed next steps:

  1. I've created files into 'extend' folder, following the plugin steps on docs:
  1. I've added Stripe apiKey on config/settings.yml
payments:
    ...
    # Additional custom payment methods should be added here
    stripe:
        active: true
        apiKey: STRIPE-API-KEY
  1. I've added plugin activation on config/settings.yml
plugins:
    payment-stripe:
        active: true # plugin should be active=true to be loaded
  1. I've added dependencies in composer.json
    "require": {
            ...
            "omnipay/stripe": "~2.0",
     }

At that point, I've needed to add a new step, that's to show a pop-up from Stripe site to ask customer credit card data to make the Stripe purchase() request.
So I've followed Stripe's site steps to show form:

Now, when I submit that form, it wil be catched on paymentFormAction() method from InvestController.php

So, my question here is, is it possible to override an existing controller, in this case, InvestController.php, like we do with templates, only creating the same file name and paths into plugin folder, as it follows:

  • extend/payment-stripe/src/Goteo/Controller/InvestController.php

or it's better to add the specific Stripe response data treatment code on general InvestController?

  • src/Goteo/Controller/InvestController.php

And if it's possible to override a controller, does it is possible to override only one method? Or when overriding, we must copy-implement all original controller code ?

I don't want to mess up all...

Thanks in advance.
Greetings

@microstudi
Copy link
Contributor

I think you should go to a different approach.
Not a bad idea to create Stripe as a plugin, but if it's a good code I rather merge in the main code as Stripe is a very popular platform. But it's ok for the moment.

However creating a plugin and adding a line in composer.json is a little bit like mixing things (although it should work). IMO either we extend the source code or put everything in the plugin. Custom composer extension in the plugin can be done as is explained here, check the files composer.json and start.php of this demo plugin: https://github.com/microstudi/goteo-project-twitter-plugin

That being said, I don't see any reference to the use of Omnipay in your comment, not using it? the point to use Ommnipay is to automate all the controller related petitions from goteo to the payment platform so there would be no need to change any view or controller code.

However, you can make a custom plugin and override almost everything. In the case of controllers, you have to define a route (override an existing one) that points to your own controller.
The way to do that is by creating your own controller and in the start.php file something like:

<?php
use Goteo\Application\App;

// Default routes
$routes = App::getRoutes();

// remove home route (for instance)
$routes->remove('home'); 
// Add a whole collection of routes:
$custom_routes = include (__DIR__ .'/src/routes.php');

// Add the official routes to our custom routes:
// we want custom routes before official routes
$custom_routes->addCollection($routes);
App::setRoutes($custom_routes);

The in src/routes.php something like:

<?php
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\RedirectResponse;

$custom_routes = new RouteCollection();

// Home replacement
$custom_routes->add('home', new Route(
    '/',
    array('_controller' => 'MyControllers\CustomIndexController::indexAction')
));
return $custom_routes;

That being said, I think adding Stripe could be accomplish by only adding a new Payment/Method/StripePaymentMethod.php file 😉

@ramoncodit
Copy link
Author

Thanks a lot @microstudi , I'll do a try as you said!

@AlexM4H
Copy link
Contributor

AlexM4H commented Mar 13, 2019

Hi @ramoncodit You are already adding a new Payment/Method/StripePaymentMethod.php file?

@AlexM4H
Copy link
Contributor

AlexM4H commented May 10, 2019

Any Updates for the Stripe payment gateway?

@rajanbarara007
Copy link

rajanbarara007 commented Jun 4, 2020

Hi @ramoncodit

I have created a new Payment/Method/StripePaymentMethod.php file to my local directory and in config/settings.yml, the following lines

# Additional custom payment methods should be added here
stripe:
    active: true
    testMode:  true # set to false to real checkouts
    username: STRIPE_USER_NAME
    password: STRIPE_PASSWORD
    apiKey:STRIPE_PUBLISHABLE_KEY

What do I need to do to make Stripe show up as a payment mode ? I am happy to help with Stripe gateway - need some guidance

Thanks
R

@rajanbarara007
Copy link

Hi @microstudi
I have created a new Payment/Method/StripePaymentMethod.php file to my local directory and in config/settings.yml, the following lines

Additional custom payment methods should be added here

stripe:
active: true
testMode: true # set to false to real checkouts
username: STRIPE_USER_NAME
password: STRIPE_PASSWORD
apiKey:STRIPE_PUBLISHABLE_KEY
What do I need to do to make Stripe show up as a payment mode ? I am happy to help with Stripe gateway - need some guidance

Thanks
Rajan

@davidbeig
Copy link
Member

Hi @rajanbarara007 ,

I see you have added those lines in the payments settings. The way to have it shown is to add is as a payment inside the Config.php using the \Goteo\Payment\Payment:addMethod() method. In case you are building a plug-in you can do it in your start.php file.

I think this is all you need to do.

In any case, do you have a github repo where we can see your progress?

Cheers,
David

@rajanbarara007
Copy link

rajanbarara007 commented Jun 17, 2020

@davidbeig Thanks for your suggestion - I am able to see the Stripe payment icon . Now I would like to start working on integrating the new PaymentIntent interface from Stripe. Where should the integration be for adding the javascript plugin on client side ?

I am getting an error "The paymentMethod parameter is required" on the payment page when I click on Contribute button. Attached is the StripePaymentMethod file.
StripePaymentMethod.php.zip

@AlexM4H
Copy link
Contributor

AlexM4H commented Jun 18, 2020

Hi @rajanbarara007,

thanks a lot for supporting the integration of stripe payment. where can we see your progress?

Best wishes
Alexander

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

No branches or pull requests

5 participants