# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover


import requests
from yithlibraryserver.compat import urlparse
        self['PAYMENTREQUEST_0_DESC'] = 'Donation'
        self['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'
        self['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale'
        self['LOCALECODE'] = 'ES'

    def add_callbacks(self, return_url, cancel_url):
        self['RETURNURL'] = return_url
        self['CANCELURL'] = cancel_url

    def add_token(self, token, payerid):
        self['TOKEN'] = token
        self['PAYERID'] = payerid


class PayPalExpressCheckout(object):

    def __init__(self, request):
        self.request = request
        self.nvp_url = request.registry.settings['paypal_nvp_url']
        self.express_checkout_url = request.registry.settings['paypal_express_checkout_url']

    def get_express_checkout_token(self, amount):
        return_url = self.request.route_url('contributions_paypal_success_callback')
        cancel_url = self.request.route_url('contributions_paypal_cancel_callback')
        payload = PayPalPayload(self.request, 'SetExpressCheckout')
        payload.add_payment_info(amount)
        payload.add_callbacks(return_url, cancel_url)

        response = requests.post(self.nvp_url, data=payload)
        if response.ok:

# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover


# Path: yithlibraryserver/contributions/paypal.py
import requests
from yithlibraryserver.compat import urlparse

        self['PAYMENTREQUEST_0_DESC'] = 'Donation'
        self['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'
        self['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale'
        self['LOCALECODE'] = 'ES'

    def add_callbacks(self, return_url, cancel_url):
        self['RETURNURL'] = return_url
        self['CANCELURL'] = cancel_url

    def add_token(self, token, payerid):
        self['TOKEN'] = token
        self['PAYERID'] = payerid


class PayPalExpressCheckout(object):

    def __init__(self, request):
        self.request = request
        self.nvp_url = request.registry.settings['paypal_nvp_url']
        self.express_checkout_url = request.registry.settings['paypal_express_checkout_url']

    def get_express_checkout_token(self, amount):
        return_url = self.request.route_url('contributions_paypal_success_callback')
        cancel_url = self.request.route_url('contributions_paypal_cancel_callback')
        payload = PayPalPayload(self.request, 'SetExpressCheckout')
        payload.add_payment_info(amount)
        payload.add_callbacks(return_url, cancel_url)

        response = requests.post(self.nvp_url, data=payload)
        if response.ok:

            data = urlparse.parse_qs(response.text)