Skip to content

Conversation

pc-coholic
Copy link
Contributor

Description
Adyen's Integration Guide requests that applications provide applicationInformation such as merchantApplication and externalPlatform.

However, this library is overwriting any provided information.

This PR addresses this issue and preserves any existing applicationInformation, only extending it with the adyenLibrary.

Tested scenarios

    def _init_api(self, env=None):
        self.adyen = Adyen.Adyen(
            app_name='pretix',
            xapikey=self.settings.test_api_key if self.event.testmode else self.settings.prod_api_key,
            # API-calls go only to -live in prod - not to -live-au or -live-us like in the frontend.
            platform=env if env else 'test' if self.event.testmode else 'live',
            live_endpoint_prefix=self.settings.prod_prefix
        )

    @property
    def api_kwargs(self):
        kwargs = {
            'merchantAccount': self.settings.test_merchant_account if self.event.testmode
            else self.settings.prod_merchant_account,
            'applicationInfo': {
                'merchantApplication': {
                    'name': 'pretix-adyen',
                    'version': PluginApp.PretixPluginMeta.version,
                },
                'externalPlatform': {
                    'name': 'pretix',
                    'version': __version__,
                    'integrator': settings.PRETIX_INSTANCE_NAME,
                }
            }
        }

        return kwargs

    def execute_refund(self, refund: OrderRefund):
        self._init_api()

        payment_info = refund.payment.info_data

        if not payment_info:
            raise PaymentException(_('No payment information found.'))

        rqdata = {
            'modificationAmount': {
                'value': self._get_amount(refund),
                'currency': self.event.currency,
            },
            'originalReference': payment_info['pspReference'],
            'merchantOrderReference': '{event}-{code}'.format(event=self.event.slug.upper(), code=refund.order.code),
            'reference': '{event}-{code}-R-{payment}'.format(event=self.event.slug.upper(), code=refund.order.code, payment=refund.local_id),
            'shopperStatement': self.statement_descriptor(refund),
            'captureDelayHours': 0,
            **self.api_kwargs
        }

        try:
            result = self.adyen.payment.refund(rqdata)
        except AdyenError as e:
            logger.exception('AdyenError: %s' % str(e))
            return

Fixed issue:
No issue has been filed beforehand

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 67.773% when pulling 64bb037 on pc-coholic:applicationInfo into 12cba40 on Adyen:develop.

@KadoBOT
Copy link
Contributor

KadoBOT commented Feb 4, 2020

Thanks for opening this PR @pc-coholic . LGTM.

@martinsrenato martinsrenato merged commit 68ae397 into Adyen:develop Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants