-
-
Notifications
You must be signed in to change notification settings - Fork 496
[18.0][ADD] payment_amazon_pay: Add new module for Amazon Pay #934
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
Open
pilarvargas-tecnativa
wants to merge
2
commits into
OCA:18.0
Choose a base branch
from
Tecnativa:18.0-add-payment_amazon_pay
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import controllers | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| </odoo> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.