Skip to content

Commit

Permalink
Merge pull request #6 from Delawen/master
Browse files Browse the repository at this point in the history
Fixing REST API
  • Loading branch information
Delawen committed Oct 19, 2020
2 parents 12060b5 + 89959f4 commit 5655177
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
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

0 comments on commit 5655177

Please sign in to comment.