DJG
DJG

Reputation: 6563

Odoo: Adding Stripe with Payment Acquirer

I am trying to integrate Stripe with Odoo. I would like to use stripe.js so my server does not have to store credit card numbers.

To try to figure out how I can do this, I looked at the open source payment_paypal add-on. What I found was this:

def _get_paypal_urls(self, cr, uid, environment, context=None):
        """ Paypal URLS """
        if environment == 'prod':
            return {
                'paypal_form_url': 'https://www.paypal.com/cgi-bin/webscr',
                'paypal_rest_url': 'https://api.paypal.com/v1/oauth2/token',
            }
        else:
            return {
                'paypal_form_url': 'https://www.sandbox.paypal.com/cgi-bin/webscr',
                'paypal_rest_url': 'https://api.sandbox.paypal.com/v1/oauth2/token',
            }

where the 'paypal_form_url' key has the URL that is included inside the action attribute of the <form> tag on the checkout page.

The way stripe.js is supposed to be included on a webpage is actually like so (from Stripe's documentation):

<form action="/charge" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh"
    data-image="/img/documentation/checkout/marketplace.png"
    data-name="Stripe.com"
    data-description="2 widgets"
    data-amount="2000">
  </script>
</form>

which obviously has arbitrary JavaScript in the middle of the form tag, so that simply setting the action attribute will not be enough to make it work. This is a problem because Odoo's template system already fills in the HTML for you.

Is there a way I can get arbitrary JavaScript to work with Odoo's built-in payment system? Is there any other way to integrate Stripe with Odoo?

Upvotes: 1

Views: 2460

Answers (2)

63wagon
63wagon

Reputation: 11

I have a website with stripe and checkout.js working.

It's a bit different from other gateways, there is really just one return URL.

I decided to add the key to the payment_acquirer model, and most of the heavy lifting into the model which inherits payment_transaction model.

Anyway, here is the form and the include for the js:

<template id="stripe_acquirer_button">
  <form id='stripe_form' action='/payment/stripe/return' method="post" target="_self">
            <input id='stripe_order_amount' type="hidden"  name='amount' t-att-value="tx_values['stripe_order_amount']"/>
            <input id='stripe_publishable_key' type="hidden" t-att-value="tx_values['stripe_publishable_key']"/>
            <input id='stripe_reference' type="hidden" name='reference' t-att-value="tx_values['stripe_reference']"/>
    <input type='hidden' name='add_returndata' t-att-value="tx_values.get('add_returndata')"/>
            <input id='stripe_token' type="hidden" name='token' value="xxx"/>
  </form>
  <button id='customButton' type="submit" width="100px"
                t-att-class="submit_class">
                <img t-if="not submit_txt" src="/payment_stripe/static/src/img/stripe_icon.png"/>
                <span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span>
      </button>

</template>

<template id="assets_common" name="global assets" inherit_id="web.assets_common">
  <xpath expr="." position="inside">
    <script src="https://checkout.stripe.com/checkout.js"></script>
        <script src="/payment_stripe/static/src/js/payment_stripe.js"></script>
  </xpath>
</template>

Upvotes: 1

azurewraith
azurewraith

Reputation: 388

I'm interested in this myself, yesterday someone posted this which looks to be a start towards what you are going for: implementing stripe checkout issues qweb for acquirer button 84467

Presumably, the t-att- prefix and wrapping in a template might help but I'm not far enough along to know for sure.

The way PayPal works in this scenario is a redirect to PayPal with a callback URL. It is sort of apples :: oranges to the way Stripe Checkout works.

If I were to hazard a guess, if the t-att eval + template worked you could wrap this in a module with its own controller to perform the actual Stripe API transactions with the token it provides you if the card is valid. Whether you use Stripe.JS or Stripe Checkout you still need to process the token server side.

If I ever figure it out, I'll post something here.

Upvotes: 1

Related Questions