Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const config = [{
strict: ["error", "function"],
"use-isnan": "error",

"jsdoc/check-tag-names": "warn",
"jsdoc/check-tag-names": ["warn", { definedTags: ["odoo-module"] }],
"jsdoc/check-types": "warn",
"jsdoc/require-param-description": "off",
"jsdoc/require-return": "off",
Expand Down Expand Up @@ -191,7 +191,7 @@ const config = [{
},

}, {
files: ["**/*.esm.js"],
files: ["**/*.esm.js", "payment_amazon_pay/static/src/js/payment_form.js"],

languageOptions: {
ecmaVersion: 2024,
Expand Down
84 changes: 84 additions & 0 deletions payment_amazon_pay/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
==========
Amazon Pay
==========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:25f860184c83e375186e40eafb6e83beaf5cf4a36a6eaa2b27db8aba953cdcb9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github
:target: https://github.com/OCA/account-payment/tree/18.0/payment_amazon_pay
:alt: OCA/account-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-payment-18-0/account-payment-18-0-payment_amazon_pay
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-payment&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Payment provider integration for `Amazon Pay
v2 <https://developer.amazon.com/docs/amazon-pay-api-v2/intro.html>`__.

Supports the EU, NA, and JP regions. Uses the Amazon Pay v2 API (RSA-PSS
signed requests) for checkout session creation, completion, and refunds.
Handles IPN notifications via a dedicated webhook endpoint.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-payment/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-payment/issues/new?body=module:%20payment_amazon_pay%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Pilar Vargas
- Cristina Hidalgo

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/account-payment <https://github.com/OCA/account-payment/tree/18.0/payment_amazon_pay>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions payment_amazon_pay/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
23 changes: 23 additions & 0 deletions payment_amazon_pay/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Amazon Pay",
"version": "18.0.1.0.0",
"category": "Accounting/Payment Providers",
"summary": "Amazon Pay payment provider for Odoo",
"license": "AGPL-3",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-payment",
"depends": ["payment"],
"external_dependencies": {"python": ["cryptography", "requests"]},
"data": [
"data/payment_provider_data.xml",
"views/payment_provider_views.xml",
"views/payment_amazon_pay_templates.xml",
],
"assets": {
"web.assets_frontend": [
"payment_amazon_pay/static/src/js/payment_form.js",
],
},
"installable": True,
"application": False,
}
1 change: 1 addition & 0 deletions payment_amazon_pay/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
97 changes: 97 additions & 0 deletions payment_amazon_pay/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import json
import logging

from odoo import http
from odoo.exceptions import ValidationError
from odoo.http import request

_logger = logging.getLogger(__name__)


def _get_tx(notification_data):
return (
request.env["payment.transaction"]
.sudo()
._get_tx_from_notification_data("amazon_pay", notification_data)
)


class AmazonPayController(http.Controller):
@http.route(
"/payment/amazon_pay/return",
type="http",
auth="public",
methods=["GET"],
csrf=False,
save_session=False,
)
def amazon_pay_return(self, reference=None, amazonCheckoutSessionId=None, **kwargs):
request.env["payment.transaction"].sudo()._handle_notification_data(
"amazon_pay",
{"reference": reference, "checkoutSessionId": amazonCheckoutSessionId},
)
return request.redirect("/payment/status")

@http.route(
"/payment/amazon_pay/cancel",
type="http",
auth="public",
methods=["GET"],
csrf=False,
save_session=False,
)
def amazon_pay_cancel(self, reference=None, amazonCheckoutSessionId=None, **kwargs):
request.env["payment.transaction"].sudo()._handle_notification_data(
"amazon_pay",
{
"reference": reference,
"checkoutSessionId": amazonCheckoutSessionId,
"statusDetails": {"state": "Canceled"},
},
)
return request.redirect("/payment/status")

@http.route(
"/payment/amazon_pay/ipn",
type="http",
auth="public",
methods=["POST"],
csrf=False,
save_session=False,
)
def amazon_pay_ipn(self, **kwargs):
raw_payload = request.httprequest.get_data(cache=False, as_text=True) or "{}"
try:
payload = json.loads(raw_payload)
except json.JSONDecodeError:
_logger.warning("Invalid Amazon Pay IPN payload: %s", raw_payload)
return request.make_response(
"invalid", headers=[("Content-Type", "text/plain")]
)

data = payload.get("Object") or payload
object_type = data.get("ObjectType") or data.get("objectType")
object_id = data.get("ObjectId") or data.get("objectId")
charge_id = data.get("chargeId")
refund_id = data.get("refundId")

try:
tx = _get_tx({"checkoutSessionId": object_id, "chargeId": charge_id})
except ValidationError:
return request.make_response(
"ignored", headers=[("Content-Type", "text/plain")]
)

if object_type in ("CHARGE", "Charge") and charge_id:
notification_data = tx.provider_id._amazon_pay_get_charge(charge_id)
elif object_type in ("REFUND", "Refund") and refund_id:
notification_data = tx.provider_id._amazon_pay_get_refund(refund_id)
else:
notification_data = tx.provider_id._amazon_pay_get_checkout_session(
object_id or tx.amazon_pay_checkout_session_id
)

notification_data.setdefault("reference", tx.reference)
notification_data.setdefault("merchantReferenceId", tx.reference)
tx._handle_notification_data("amazon_pay", notification_data)
return request.make_response("ok", headers=[("Content-Type", "text/plain")])
17 changes: 17 additions & 0 deletions payment_amazon_pay/data/payment_provider_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="payment_provider_amazon_pay" model="payment.provider">
<field name="name">Amazon Pay</field>
<field name="code">amazon_pay</field>
<field
name="image_128"
type="base64"
file="payment_amazon_pay/static/img/amazon_pay.png"
/>
<field name="module_id" ref="base.module_payment_amazon_pay" />
<field
name="payment_method_ids"
eval="[Command.set([ref('payment.payment_method_amazon_pay')])]"
/>
</record>
Comment thread
pilarvargas-tecnativa marked this conversation as resolved.
</odoo>
Loading
Loading