Changeset 12029


Ignore:
Timestamp:
21 Nov 2014, 13:07:57 (10 years ago)
Author:
uli
Message:

Provide a global PayPal? SDK activation.

Location:
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/paypal.py

    r12026 r12029  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18"""Support for PayPal payments.
     19"""
    1820import ConfigParser
    1921import paypalrestsdk
     
    5355
    5456
     57def configure_sdk(path):
     58    """Configure the PayPal SDK with values from config in `path`.
     59
     60    Parse paypal configuration from file in `path` and set
     61    configuration in SDK accordingly.
     62
     63    Returns a dict with values from config file and path set.
     64
     65    This function will normally be called during start-up and only
     66    this one time.
     67
     68    It is neccessary to authorize later calls to other part of the
     69    PayPal API.
     70    """
     71    conf = parse_paypal_config(path)
     72    paypalrestsdk.configure({
     73        'mode': conf['mode'],
     74        'client_id': conf['client_id'],
     75        'client_secret': conf['client_secret'],
     76        })
     77    conf['path'] = path
     78    return conf
     79
     80
    5581def get_access_token():
    5682    """Get an access token for further calls.
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_paypal.py

    r12027 r12029  
    2020import tempfile
    2121import unittest
     22import paypalrestsdk
    2223from zope.component import getGlobalSiteManager, queryUtility
    2324from waeup.ikoba.interfaces import IPayPalConfig
    2425from waeup.ikoba.payments.paypal import (
    2526    get_paypal_config_file_path, parse_paypal_config, get_access_token,
     27    configure_sdk,
    2628    )
    2729from waeup.ikoba.testing import (
     
    7981        assert result['mode'] == "sandbox"
    8082
     83    def test_configure_sdk(self):
     84        # we can configure the paypal sdk
     85        path = os.path.join(self.workdir, 'sample.cfg')
     86        open(path, 'w').write(
     87            "[rest-client]\n"
     88            "id = my-special-id\n"
     89            )
     90        result = configure_sdk(path)
     91        assert result['client_id'] == 'my-special-id'
     92        assert result['client_secret'] is None
     93        assert result['mode'] == "sandbox"
     94        assert paypalrestsdk.api.__api__.mode == 'sandbox'
     95        assert paypalrestsdk.api.__api__.client_id == 'my-special-id'
     96
    8197
    8298class FunctionalPaypalTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.