goteo
goteo copied to clipboard
Add new payment method
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: [email protected]
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:
- Added code block on config/settings.yml, let's say:
stripe:
active: true
testMode: true # set to false to real checkouts
username: [email protected]
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
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!
Hi! first of all, thanks in advance for your quick response! I'll start working as you have suggested me.
Thanks!
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:
- I've created files into 'extend' folder, following the plugin steps on docs:
- http://goteofoundation.github.io/goteo/docs/developers/extend.html
- 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
- I've added plugin activation on config/settings.yml
plugins:
payment-stripe:
active: true # plugin should be active=true to be loaded
- 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:
- https://stripe.com/docs/checkout#integration-simple into payment_method template, overriding it into plugin folder:
- extend/payment-stripe/Resources/templates/responsive/invest/payment_method.php
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
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 😉
Thanks a lot @microstudi , I'll do a try as you said!
Hi @ramoncodit You are already adding a new Payment/Method/StripePaymentMethod.php
file?
Any Updates for the Stripe payment gateway?
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
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
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
@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
Hi @rajanbarara007,
thanks a lot for supporting the integration of stripe payment. where can we see your progress?
Best wishes Alexander