Ejemplo n.º 1
0
 def __init__(self):
     self.client_id = settings.PAYPAL_CLIENT_ID
     self.client_secret = settings.PAYPAL_SECRET
     # TODO: do something with _production_ environment
     self.environment = SandboxEnvironment(client_id=self.client_id,
                                           client_secret=self.client_secret)
     self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 2
0
    def __init__(self):
        self.client_id = os.environ.get('PAYPAL_CLIENT_ID')
        self.client_secret = os.environ.get('PAYPAL_SECRET_KEY')

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 3
0
def processing_payment(request, assignment_id):
    assignment = get_object_or_404(Assignment, id=assignment_id)
    if request.method == 'POST':
        environment = LiveEnvironment(client_id=settings.PAYPAL_CLIENT_ID,
                                      client_secret=settings.PAYPAL_SECRET_ID)
        client = PayPalHttpClient(environment)
        create_order = OrdersCreateRequest()
        create_order.request_body({
            "intent":
            "CAPTURE",
            "purchase_units": [{
                "amount": {
                    "currency_code": "USD",
                    "value": assignment.price,
                    "breakdown": {
                        "item_total": {
                            "currency_code": "USD",
                            "value": assignment.price
                        }
                    },
                },
            }]
        })

        response = client.execute(create_order)
        data = response.result.__dict__['_dict']
        return JsonResponse(data)
Ejemplo n.º 4
0
    def testPayPalHttpClient_withRefreshToken_fetchesAccessTokenWithRefreshToken(
            self):
        request = SimpleRequest("/", "POST")
        self.stub_request_with_response(request)

        self.client = PayPalHttpClient(self.environment(),
                                       refresh_token="refresh-token")

        self.stubaccesstokenrequest(refresh_token="refresh-token")

        self.client.execute(request)

        self.assertEqual(2, len(responses.calls))

        accesstokenrequest = responses.calls[0].request
        self.assertEqual(self.environment().base_url + "/v1/oauth2/token",
                         accesstokenrequest.url)
        self.assertEqual("application/x-www-form-urlencoded",
                         accesstokenrequest.headers["Content-Type"])

        expectedauthheader = "Basic {0}".format(
            base64.b64encode(("{0}:{1}".format(
                self.environment().client_id,
                self.environment().client_secret)).encode()).decode())
        self.assertEqual(expectedauthheader,
                         accesstokenrequest.headers["Authorization"])
        self.assertTrue("grant_type=refresh_token" in accesstokenrequest.body)
        self.assertTrue(
            "refresh_token=refresh-token" in accesstokenrequest.body)
Ejemplo n.º 5
0
    def ready(self):
        try:

            from payment.models.main import PaymentProvider
            from payment.models.main import PaymentMethod

            prepayment, created = PaymentProvider.objects.get_or_create(
                api="Prepayment")
            bill, created = PaymentProvider.objects.get_or_create(api="Bill")
            paypal, created = PaymentProvider.objects.get_or_create(
                api="PayPal")

            pp_method, created = PaymentMethod.objects.get_or_create(
                name="Prepayment", provider=prepayment)
            bill_method, created = PaymentMethod.objects.get_or_create(
                name="Bill", provider=bill)
            paypal_method, created = PaymentMethod.objects.get_or_create(
                name="PayPal", provider=paypal)

            provider = PaymentProvider.objects.filter(api__contains="PayPal")
            if provider.count() > 0:
                if provider[0].use_sandbox:
                    self.paypal_environment = SandboxEnvironment(
                        client_id=provider[0].user_name,
                        client_secret=provider[0].secret)
                else:
                    self.paypal_environment = LiveEnvironment(
                        client_id=provider[0].user_name,
                        client_secret=provider[0].secret)
                self.paypal_client = PayPalHttpClient(self.paypal_environment)
        except:
            print("DB not migrated")
Ejemplo n.º 6
0
 def __init__(self, request, donation=None, subscription=None, **kwargs):
     super().__init__(request, donation, subscription)
     # set paypal settings object
     self.settings = getPayPalSettings()
     # init paypal http client
     self.client = PayPalHttpClient(self.settings.environment)
     # saves all remaining kwargs into the manager, e.g. order_id, order_status
     self.__dict__.update(kwargs)
Ejemplo n.º 7
0
 def setUp(self):
     client_id = os.environ[
         "PAYPAL_CLIENT_ID"] if 'PAYPAL_CLIENT_ID' in os.environ else "<<PAYPAL-CLIENT-ID>>"
     client_secret = os.environ[
         "PAYPAL_CLIENT_SECRET"] if 'PAYPAL_CLIENT_SECRET' in os.environ else "<<PAYPAL-CLIENT-SECRET>>"
     self.environment = SandboxEnvironment(client_id=client_id,
                                           client_secret=client_secret)
     self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 8
0
def configuration():
    client_id = settings.PAYPAL_CLIENT_ID
    client_secret = settings.PAYPAL_CLIENT_SECRET
    environment = SandboxEnvironment(client_id=client_id,
                                     client_secret=client_secret)
    client = PayPalHttpClient(environment)

    return client
Ejemplo n.º 9
0
    def __init__(self):
        self.client_id = os.environ['PAYPAL_ID']
        self.client_secret = os.environ['PAYPAL_SECRET']

        """In production, use LiveEnvironment."""
        self.environment = SandboxEnvironment(client_id = self.client_id, client_secret = self.client_secret)

        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 10
0
    def __init__(self):
        self.client_id = "AQOM5xwx-dY-L3u_bFJF8lQMIJLJBa-uFwsoC1rsPjex_lqKiVzQkNdafP13X5bw_97h2u4FCRdnWKVq"
        self.client_secret = "ENLewOXqOI3FMi2YJXgT4XqWosGeF5V-7GaaMaHhij61Et5NgqCLeBzHEhCvkE-gjtcpNqvw3uyrJhHn"

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)

        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 11
0
def getClient(request):

    paypal_client_id = settings.PAYPAL_CLIENT_ID
    paypal_secret_id = settings.PAYPAL_SECRET_ID

    env = SandboxEnvironment(client_id=paypal_client_id,
                             client_secret=paypal_secret_id)
    client = PayPalHttpClient(env)
    return client
Ejemplo n.º 12
0
    def __init__(self) -> None:
        """Инициализирует сессию работы с системой PayPal."""

        # Creating an environment
        environment = SandboxEnvironment(client_id=PAYPAL_CLIENT_ID, client_secret=PAYPAL_CLIENT_SECRET)
        self.client = PayPalHttpClient(environment)
        self.process_notification = {  # todo should this be here?
            PayPalStrings.WEBHOOK_APPROVED.value: self.capture,
            PayPalStrings.WEBHOOK_COMPLETED.value: self.fulfill,
        }
Ejemplo n.º 13
0
 def __init__(self):
     if PayPalSettings.USE_SANDBOX:
         self.environment = SandboxEnvironment(
             client_id=PayPalSettings.CLIENT_ID,
             client_secret=PayPalSettings.CLIENT_SECRET)
     else:
         self.environment = LiveEnvironment(
             client_id=PayPalSettings.CLIENT_ID,
             client_secret=PayPalSettings.CLIENT_SECRET)
     self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 14
0
 def __init__(self):
     sandbox = True
     if sandbox:
         self.client_id = ''
         self.client_secret = ''
         self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)
     else: 
         self.client_id = ''
         self.client_secret = ''
         self.environment = LiveEnvironment(client_id=self.client_id, client_secret=self.client_secret)
     self.client = PayPalHttpClient(self.environment)
    def __init__(self):
        self.client_id = "AZSM8h2MflxGM0iBCmrJMyTJFtlIn4WIwZS-J6OgU6VLX0S4lgNp8xhVv1RTwL5xfzjw6jRqHdT7iOrr"
        self.client_secret = "EMiJ2RjZa3iXHrTTiQhT2_RdzCQK-_IEzQV9S17EmuvEbOdJkMsbdzZuz4vR2aSsQYcvGchIxO4v2z4Z"
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 16
0
    def __init__(self):
        self.client_id = "Ac5WPsCMuD4X3uu--d5hJ8c13mLF9b-JshG2sapdD4gqhUyMvZ_9_OXZ3XbIbnsDVCZr6FZ89LUi08Dn"
        self.client_secret = "EL06rcocvyIbGteIIpz1HkXRk2lsuxy8ZQsCmeVpWNobYEbQ-ZbIZDVx0JDzW0mL1CdgTzcEa2PkFT5z"
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 17
0
    def __init__(self, data: dict):
        super(PayGateWay, self).__init__(data)
        _env_config = {
            'client_id': self.config['client_id'],
            'client_secret': self.config['client_secret']
        }

        if self.config['sandbox']:
            environment = SandboxEnvironment(**_env_config)
        else:
            environment = LiveEnvironment(**_env_config)
        self.paypal = PayPalHttpClient(environment)
Ejemplo n.º 18
0
    def __init__(self):
        self.client_id = "AT9MrrKnz-Ap6nKtesw7UWKFk5DgBNrytIa0Ea2_cjBAaKgU2g3_a-vUNZ-KArTt4CWf6fVsj8D2HBpP"
        self.client_secret = "EJnzejjJuoXfbGxLt-76nuDs55pmbLUXucQGqMArDn9zcl2NJI3M7cdja4NTFf6yJbQzvavvKLQnUsoc"
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 19
0
    def __init__(self):
        # Sandbox
        # self.client_id = "AWLMBI3BwXhtXFpMZw-BnZLMvw3NjS_52qMjdQPx-e7Oe7Q7_x33nyg4EXcMHVu9ZhdNw_0CNfpgOR2M"
        # self.client_secret = "EIAR_G5gIaS2A2ZDWATudaRzTooP_kkP8PTN4GP11v8RgQfhSiIEiRJNK-k-oESr2lf4cixIp6Tuudci"
        # Live
        self.client_id = "AUfE4lMYpalZDXKaXrU-OBU3EpQkEqK8TlpiYplZ3mdJAjtaeSkrt1iktz0GFlMgdPKviucsr5F8BD0G"
        self.client_secret = "EBGppM5pfBWp-VsvUWeV72-vQUNbvReUimfmPmYfzsqoWM8QpR-gUSTVHythyaXv8B--2ghja28Gu2xb"

        # self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)
        self.environment = LiveEnvironment(client_id=self.client_id,
                                           client_secret=self.client_secret)
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 20
0
    def __init__(self):
        self.client_id = os.getenv("PAYPAL_SANDBOX_CLIENT_ID")
        self.client_secret = os.getenv("PAYPAL_SANDBOX_CLIENT_SECRET")
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use ProductionEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 21
0
def create_paypal_order(session, donation):
    paypalSettings = getPayPalSettings()
    client = PayPalHttpClient(paypalSettings.environment)

    req = OrdersCreateRequest()
    # set dictionary object in session['extra_test_headers'] in TestCases
    if session.get('extra_test_headers', None) and donation.is_test:
        for key, value in session.get('extra_test_headers').items():
            req.headers[key] = value
    req.prefer('return=representation')
    req.request_body(build_onetime_request_body(donation))
    return client.execute(req)
Ejemplo n.º 22
0
 def __init__(self):
     self.client_id = settings.PAYPAL_CLIENT_ID
     self.client_secret = settings.PAYPAL_CLIENT_SECRET
     """Setting up and Returns PayPal SDK environment with PayPal Access credentials.
        For demo purpose, we are using SandboxEnvironment. In production this will be
        LiveEnvironment."""
     self.environment = SandboxEnvironment(client_id=self.client_id,
                                           client_secret=self.client_secret)
     """ Returns PayPal HTTP client instance with environment which has access
         credentials context. This can be used invoke PayPal API's provided the
         credentials have the access to do so. """
     self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 23
0
    def __init__(self):
        self.client_id = "ASFQSWdaUNf4UQR99fImi867BckGMxRMfqgQEYbMM9z-OAt8368XH757eoYvn0A-CiZjK3dfWY78u4Wj"
        self.client_secret = "EM_b9-A1qphs-W38e0sPNtvRDYuad12nKk5yzA-gw1PFdWDalZWfTbR6jGhIGJdEYgZ6HETeikoDlT2C"
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 24
0
    def __init__(self):
        credentials = {
            'client_id': settings.PAYPAL_CLIENT_ID,
            'client_secret': settings.PAYPAL_CLIENT_SECRET,
        }

        if getattr(settings, 'PAYPAL_SANDBOX_MODE', True):
            environment = SandboxEnvironment(**credentials)
        else:
            environment = LiveEnvironment(**credentials)

        self.client = PayPalHttpClient(environment)
Ejemplo n.º 25
0
    def __init__(self):
        self.client_id = "AREn1ZxGsFz36Q5jDcZo0Eia2VOEzvAyLDcrwvxiQAyH_yhiXRGgtLgNxUTG2bljtBlAZzIAFtnsghqz"
        self.client_secret = "EKDG736JjGPnoey51QlRBVc3oZJVuYyXDcKBANtR_5ULi00zOGMVeY0ptQQUp-vVbgoW38QJfp4BQxss"
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id,
                                              client_secret=self.client_secret)
        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 26
0
    def __init__(self):
        self.client_id = PAYPAL_CLIENT_ID
        self.client_secret = PAYPAL_CLIENT_SECRET

        # choose live or sandbox Environment
        if PAYPAL_ENVIRONMENT == 'live':
            self.environment = LiveEnvironment(
                client_id=self.client_id, client_secret=self.client_secret)
        else:
            self.environment = SandboxEnvironment(
                client_id=self.client_id, client_secret=self.client_secret)

        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 27
0
    def __init__(self):
        # self.client_id = "AQCX7hsi7c9wiHFuHzb8c-CWn7P6Y1tW0znMXpisx7Khlmh3FR81lbwqqQqk31WQqkvoRucgEPTyo0wZ"
        # self.client_secret = "EGX5KF7bx_awycoq0CI6KoupvUCPcyX1U8ZjCtMaoWQsDygcV_EKBzw60tfCCsAhI8ZwrwkHcPSZ-JJa"

        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use ProductionEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)

        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 28
0
    def __init__(self):
        self.client_id = "AUSp21wTdzaQnRU0d5qmvYKbtNQiWV3c2E6_Ht39NQDN1mY3VgJ4WD_ZexD-48a39lKwjBHhQGvaQ-gz"
        self.client_secret = "EPtPGQXhdcUdUT1Z5sQtr2pQ1HsWggisaU9POVBIqF3LLb8poQxEveQcYcv3_kOieupHVy5jtO8GFezO"

        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)

        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
Ejemplo n.º 29
0
def get_paypal_client():
    # Creating Access Token for Sandbox
    if settings.ENV == 'LOCAL':
        initializer = SandboxEnvironment
    else:
        initializer = LiveEnvironment

    environment = initializer(
        client_id=settings.PAYPAL_CLIENT_ID,
        client_secret=settings.PAYPAL_SECRET
    )

    return PayPalHttpClient(environment)
Ejemplo n.º 30
0
    def __init__(self):
        self.client_id = settings.PAYPAL_API_KEY[0]
        self.client_secret = settings.PAYPAL_SECRET[0]

        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""

        self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)

        """ Returns PayPal HTTP client instance with environment that has access
            credentials context. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)