def getBalance(self,interfaceCheck):
     pp = PayPalInterface(API_USERNAME=interfaceCheck['USER'],
                          API_PASSWORD=interfaceCheck['PWD'],
                          API_SIGNATURE=interfaceCheck['SIGNATURE'],
                          API_ENVIRONMENT='PRODUCTION')
     response = pp._call("GetBalance")
     return response['L_AMT0']
def _get_paypal_interface():
    return PayPalInterface(
        API_USERNAME=settings.PAYPAL_API_USERNAME,
        API_PASSWORD=settings.PAYPAL_API_PASSWORD,
        API_SIGNATURE=settings.PAYPAL_API_SIGNATURE,
        API_ENVIRONMENT=settings.PAYPAL_API_ENVIRONMENT,
    )
Exemple #3
0
 def __init__(self, options=None, *args, **kwargs):
     merchant_settings = getattr(settings, "MERCHANT_SETTINGS")
     if not merchant_settings and not (merchant_settings.get("pay_pal") or options):
         raise GatewayNotConfigured("The '%s' gateway is not correctly "
                                    "configured." % self.display_name)
     pay_pal_settings = options or merchant_settings["pay_pal"]
     self.paypal = PayPalInterface(**pay_pal_settings)
 def test_returns_certificate_call_params(self):
     interface = PayPalInterface(**self.configs_certificate)
     call_kwargs = {'param_a': 'a1', 'param_b': 'b2'}
     call_params = interface._get_call_params('some_method', **call_kwargs)
     version = interface.config.API_VERSION
     expected_call_params = {'data': {'USER': '******',
                                      'PWD': 'test_password',
                                      'PARAM_A': 'a1',
                                      'PARAM_B': 'b2',
                                      'METHOD': 'some_method',
                                      'VERSION': version},
                             'cert': ('test_cert_filename',
                                      'test_key_filename'),
                             'url': interface.config.API_ENDPOINT,
                             'timeout': interface.config.HTTP_TIMEOUT,
                             'verify': interface.config.API_CA_CERTS}
     self.assertEqual(expected_call_params, call_params)
 def test_returns_unipay_call_params(self):
     interface = PayPalInterface(**self.configs_3token)
     interface.config.API_AUTHENTICATION_MODE = 'UNIPAY'
     interface.config.UNIPAY_SUBJECT = 'test_subject'
     call_kwargs = {'param_a': 'a1', 'param_b': 'b2'}
     call_params = interface._get_call_params('some_method', **call_kwargs)
     version = interface.config.API_VERSION
     expected_call_params = {'data': {'SUBJECT': 'test_subject',
                                      'PARAM_A': 'a1',
                                      'PARAM_B': 'b2',
                                      'METHOD': 'some_method',
                                      'VERSION': version},
                             'cert': None,
                             'url': interface.config.API_ENDPOINT,
                             'timeout': interface.config.HTTP_TIMEOUT,
                             'verify': interface.config.API_CA_CERTS}
     self.assertEqual(expected_call_params, call_params)
Exemple #6
0
 def test_returns_certificate_call_params(self):
     interface = PayPalInterface(**self.configs_certificate)
     call_kwargs = {'param_a': 'a1', 'param_b': 'b2'}
     call_params = interface._get_call_params('some_method', **call_kwargs)
     version = interface.config.API_VERSION
     expected_call_params = {
         'data': {
             'USER': '******',
             'PWD': 'test_password',
             'PARAM_A': 'a1',
             'PARAM_B': 'b2',
             'METHOD': 'some_method',
             'VERSION': version
         },
         'cert': ('test_cert_filename', 'test_key_filename'),
         'url': interface.config.API_ENDPOINT,
         'timeout': interface.config.HTTP_TIMEOUT,
         'verify': interface.config.API_CA_CERTS
     }
     self.assertEqual(expected_call_params, call_params)
Exemple #7
0
 def test_returns_unipay_call_params(self):
     interface = PayPalInterface(**self.configs_3token)
     interface.config.API_AUTHENTICATION_MODE = 'UNIPAY'
     interface.config.UNIPAY_SUBJECT = 'test_subject'
     call_kwargs = {'param_a': 'a1', 'param_b': 'b2'}
     call_params = interface._get_call_params('some_method', **call_kwargs)
     version = interface.config.API_VERSION
     expected_call_params = {
         'data': {
             'SUBJECT': 'test_subject',
             'PARAM_A': 'a1',
             'PARAM_B': 'b2',
             'METHOD': 'some_method',
             'VERSION': version
         },
         'cert': None,
         'url': interface.config.API_ENDPOINT,
         'timeout': interface.config.HTTP_TIMEOUT,
         'verify': interface.config.API_CA_CERTS
     }
     self.assertEqual(expected_call_params, call_params)
Exemple #8
0
    def _getPayPal(self):

        return PayPalInterface(API_USERNAME=PP_API_USERNAME,
                               API_PASSWORD=PP_API_PASSWORD,
                               API_SIGNATURE=PP_API_SIGNATURE)
Exemple #9
0
 def test_raises_error_for_multiple_configs(self):
     interface = PayPalInterface(**self.configs_certificate)
     interface.config.API_USERNAME = None
     interface.config.API_PASSWORD = None
     with self.assertRaisesRegexp(PayPalConfigError, r'PWD.*USER'):
         interface._get_call_params('some_method', some_param=123)
Exemple #10
0
 def test_raises_error_for_single_none_config(self):
     interface = PayPalInterface(**self.configs_certificate)
     interface.config.API_USERNAME = None
     with self.assertRaisesRegexp(PayPalConfigError, 'USER'):
         interface._get_call_params('some_method', some_param=123)
Exemple #11
0
    def __call__(self):
        config = self._get_config()
        if config is None:
            raise ValueError("paypal configuration settings not available")

        return PayPalInterface(config=config)
 def test_raises_error_for_multiple_configs(self):
     interface = PayPalInterface(**self.configs_certificate)
     interface.config.API_USERNAME = None
     interface.config.API_PASSWORD = None
     with self.assertRaisesRegexp(PayPalConfigError, r'PWD.*USER'):
         interface._get_call_params('some_method', some_param=123)
 def test_raises_error_for_single_none_config(self):
     interface = PayPalInterface(**self.configs_certificate)
     interface.config.API_USERNAME = None
     with self.assertRaisesRegexp(PayPalConfigError, 'USER'):
         interface._get_call_params('some_method', some_param=123)
Exemple #14
0
class PayPalGateway(Gateway):
    default_currency = "USD"
    supported_countries = ["US"]
    supported_cardtypes = [Visa, MasterCard, AmericanExpress, Discover]
    homepage_url = "https://merchant.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=merchant/wp_pro"
    display_name = "PayPal Website Payments Pro"

    def __init__(self, options=None, *args, **kwargs):
        merchant_settings = getattr(settings, "MERCHANT_SETTINGS")
        if not merchant_settings and not (merchant_settings.get("pay_pal") or options):
            raise GatewayNotConfigured("The '%s' gateway is not correctly "
                                       "configured." % self.display_name)
        pay_pal_settings = options or merchant_settings["pay_pal"]
        self.paypal = PayPalInterface(**pay_pal_settings)

    @property
    def service_url(self):
        # Implemented in django-paypal
        raise NotImplementedError

    def purchase(self, money, credit_card, options=None):
        """Using PAYPAL DoDirectPayment, charge the given
        credit card for specified money"""
        if not options:
            options = {}
        if not self.validate_card(credit_card):
            raise InvalidCard("Invalid Card")

        params = {}
        params['creditcardtype'] = credit_card.card_type.card_name
        params['acct'] = credit_card.number
        params['expdate'] = '%02d%04d' % (credit_card.month, credit_card.year)
        params['cvv2'] = credit_card.verification_value
        params['ipaddress'] = options['request'].META.get("REMOTE_ADDR", "")
        params['amt'] = money

        if options.get("email"):
            params['email'] = options["email"]

        address = options.get("billing_address", {})
        first_name = None
        last_name = None
        try:
            first_name, last_name = address.get("name", "").split(" ")
        except ValueError:
            pass
        params['firstname'] = first_name or credit_card.first_name
        params['lastname'] = last_name or credit_card.last_name
        params['street'] = address.get("address1", '')
        params['street2'] = address.get("address2", "")
        params['city'] = address.get("city", '')
        params['state'] = address.get("state", '')
        params['countrycode'] = address.get("country", '')
        params['zip'] = address.get("zip", '')
        params['phone'] = address.get("phone", "")

        shipping_address = options.get("shipping_address", None)
        if shipping_address:
            params['shiptoname'] = shipping_address["name"]
            params['shiptostreet'] = shipping_address["address1"]
            params['shiptostreet2'] = shipping_address.get("address2", "")
            params['shiptocity'] = shipping_address["city"]
            params['shiptostate'] = shipping_address["state"]
            params['shiptocountry'] = shipping_address["country"]
            params['shiptozip'] = shipping_address["zip"]
            params['shiptophonenum'] = shipping_address.get("phone", "")

        #wpp = PayPalWPP(options['request'])
        try:
            response = self.paypal.do_direct_payment(**params)
            #response = wpp.doDirectPayment(params)
            transaction_was_successful.send(sender=self,
                                            type="purchase",
                                            response=response)
        except PayPalFailure, e:
            transaction_was_unsuccessful.send(sender=self,
                                              type="purchase",
                                              response=e)
            # Slight skewness because of the way django-paypal
            # is implemented.
            return {"status": "FAILURE", "response": e}
        return {"status": response.ack.upper(), "response": response}