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

Fixing REST API #6

Merged
merged 4 commits into from
Oct 19, 2020
Merged
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
24 changes: 6 additions & 18 deletions pretix_mercadopago/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def settings_content_render(self, request):
settings_content = "<div class='alert alert-info'>%s<br /><code>%s</code></div>" % (
_('Please configure a MercadoPago Webhook to the following endpoint in order '
'to automatically cancel orders when payments are refunded externally.'),
build_global_uri('plugins:pretix_mercadopago:webhook')
build_absolute_uri(request.event, 'plugins:pretix_mercadopago:webhook')
)

if self.event.currency is not self.settings.get('currency'):
Expand Down Expand Up @@ -352,27 +352,15 @@ def matching_id(self, payment: OrderPayment):
# Will be called to get an ID for a matching this payment when comparing
# pretix records with records of an external source.
# This should return the main transaction ID for your API.
sale_id = None
for trans in payment.info_data.get('transactions', []):
for res in trans.get('related_resources', []):
if 'sale' in res and 'id' in res['sale']:
sale_id = res['sale']['id']
return sale_id or payment.info_data.get('id', None)
return payment.info_data.get('external_reference', None)

def api_payment_details(self, payment: OrderPayment):
# Will be called to populate the details parameter of the payment in the REST API.
sale_id = None
for trans in payment.info_data.get('transactions', []):
for res in trans.get('related_resources', []):
if 'sale' in res and 'id' in res['sale']:
sale_id = res['sale']['id']
# Will be called to populate the details parameter
# of the payment in the REST API.
return {
"payer_email": payment.info_data.get('payer', {}).get('payer_info', {}).get('email'),
"payer_id": payment.info_data.get('payer', {}).get('payer_info', {}).get('payer_id'),
"cart_id": payment.info_data.get('cart', None),
"payment_id": payment.info_data.get('id', None),
"sale_id": sale_id,
"payment_info": payment.info
}

####################################################################
# Utility functions #
####################################################################
Expand Down
2 changes: 1 addition & 1 deletion pretix_mercadopago/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
views.admin_view, name='backend'),
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/mercadopago/disconnect/',
oauth_disconnect, name='oauth.disconnect'),
url(r'^_mercadopago/webhook/$', success, name='webhook'),
url(r'^mercadopago/webhook/$', success, name='webhook'),
]
2 changes: 1 addition & 1 deletion pretix_mercadopago/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pretix.multidomain.urlreverse import eventreverse
from pretix_mercadopago.payment import Mercadopago

logger = logging.getLogger('pretix.plugins.meli')
logger = logging.getLogger('pretix.plugins.mercadopago')


def admin_view(request, *args, **kwargs):
Expand Down