Beispiel #1
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)
Beispiel #2
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")
Beispiel #3
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)
    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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
 def __init__(self):
     self.client_id = os.environ.get('PAYPAL_CLIENT_ID')
     self.client_secret = os.environ.get('PAYPAL_SECRET')
     """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)
     self.environment = LiveEnvironment(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)
    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)
Beispiel #9
0
    def __init__(self, clientID, secretID, test=True):
        self.client_id = clientID
        self.client_secret = secretID
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use ProductionEnvironment."""

        if test:
            self.environment = SandboxEnvironment(
                client_id=self.client_id, client_secret=self.client_secret)
        else:
            self.environment = LiveEnvironment(
                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)
Beispiel #10
0
    def __init__(self):
        if settings.PAYPAL_USE_SANDBOX:
            environment = SandboxEnvironment(
                client_id=settings.PAYPAL_SANDBOX_CLIENT_ID,
                client_secret=settings.PAYPAL_SANDBOX_SECRET_KEY,
            )
        else:
            environment = LiveEnvironment(
                client_id=settings.PAYPAL_LIVE_CLIENT_ID,
                client_secret=settings.PAYPAL_LIVE_SECRET_KEY,
            )

        # 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(environment)
Beispiel #11
0
def get_paypal_client(**connection_params):
    """Set up and return PayPal Python SDK environment with PayPal access credentials.

    This sample uses SandboxEnvironment. In production, use LiveEnvironment.
    """
    client_id = connection_params.get("client_id")
    private_key = connection_params.get("private_key")
    sandbox_mode = connection_params.get("sandbox_mode")
    if sandbox_mode:
        environment = SandboxEnvironment(client_id=client_id,
                                         client_secret=private_key)
    else:
        environment = LiveEnvironment(client_id=client_id,
                                      client_secret=private_key)
    """Returns PayPal HTTP client instance with environment that has access
    credentials context. Use this instance to invoke PayPal APIs, provided the
    credentials have access. """
    return PayPalHttpClient(environment)
Beispiel #12
0
    def __init__(self):
        config = configparser.ConfigParser()
        config.read("site.cfg")

        self.client_id = config.get('PAYPAL', 'CLIENT_ID')
        self.client_secret = config.get('PAYPAL', 'SECRET')
        """Set up and return PayPal Python SDK environment with PayPal access credentials.
           This sample uses SandboxEnvironment. In production, use LiveEnvironment."""
        if config.get('DEFAULT', 'ENVIRONMENT') == 'development':
            self.environment = SandboxEnvironment(
                client_id=self.client_id, client_secret=self.client_secret)
        else:
            self.environment = LiveEnvironment(
                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)
Beispiel #13
0
def capture(request, order_id, assignment_id):
    assignment = get_object_or_404(Assignment, id=assignment_id)
    if request.method == "POST":
        capture_order = OrdersCaptureRequest(order_id)
        Order.objects.create(token=order_id,
                             total=assignment.price,
                             emailAddress=assignment.creator.email,
                             assignment=assignment,
                             paid=True,
                             client=assignment.creator,
                             writer=assignment.writer,
                             support=assignment.support)
        environment = LiveEnvironment(client_id=settings.PAYPAL_CLIENT_ID,
                                      client_secret=settings.PAYPAL_SECRET_ID)
        client = PayPalHttpClient(environment)

        response = client.execute(capture_order)
        data = response.result.__dict__['_dict']

        return JsonResponse(data)
    else:
        return JsonResponse({'details': "invalid request"})
Beispiel #14
0
def getPayPalSettings():
    siteSettings = get_site_settings_from_default_site()
    if (siteSettings.sandbox_mode):
        environment = SandboxEnvironment(
            client_id=siteSettings.paypal_sandbox_api_client_id,
            client_secret=siteSettings.paypal_sandbox_api_secret_key)
        api_url = 'https://api-m.sandbox.paypal.com'
        return SettingsPayPal(siteSettings.sandbox_mode,
                              siteSettings.paypal_sandbox_api_product_id,
                              siteSettings.paypal_sandbox_api_client_id,
                              siteSettings.paypal_sandbox_api_secret_key,
                              siteSettings.paypal_sandbox_api_webhook_id,
                              environment, api_url)
    environment = LiveEnvironment(
        client_id=siteSettings.paypal_api_client_id,
        client_secret=siteSettings.paypal_api_secret_key)
    api_url = 'https://api-m.paypal.com'
    return SettingsPayPal(siteSettings.sandbox_mode,
                          siteSettings.paypal_api_product_id,
                          siteSettings.paypal_api_client_id,
                          siteSettings.paypal_api_secret_key,
                          siteSettings.paypal_api_webhook_id, environment,
                          api_url)
Beispiel #15
0
 def __init__(self):
     self.client_id = getattr(settings, 'PAYPAL_CLIENT_ID', None)
     self.client_secret = getattr(settings, 'PAYPAL_CLIENT_SECRET', None)
     self.environment = LiveEnvironment(client_id=self.client_id,
                                        client_secret=self.client_secret)
     self.client = PayPalHttpClient(self.environment)
Beispiel #16
0
    def post(self):
        try:
            data = request.get_json()
            identity = get_jwt_identity()
            validation = order.validate_razorpay_paypal_cod_order(data)
            if validation['isValid']:
                if identity['id']:
                    args = {
                        'user_id':
                        identity['id'],
                        'user_amount':
                        data['amount'],
                        'user_display_amount':
                        data['displayAmount'],
                        'order_id':
                        data['orderId'],
                        'coupon_id':
                        data['couponId'] if 'couponId' in data else None
                    }
                    # Price check

                    result = run_db_query(
                        'select _finaltotalvalue, status from '
                        ' store.fncheckprice('
                        '_user_id=>%(user_id)s, '
                        '_order_id=>%(order_id)s, '
                        '_coupon_id=>%(coupon_id)s, '
                        '_webtotalvalue=>%(user_amount)s )', args,
                        'price check call', True)

                    if result == 'error':
                        raise Exception
                    elif result['status']:
                        # Creating Access Token for Sandbox
                        client_id = secrets['LIVE_PAYPAL_ID']
                        client_secret = secrets['LIVE_PAYPAL_SECRET']

                        # Creating an environment
                        # environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret)
                        environment = LiveEnvironment(
                            client_id=client_id, client_secret=client_secret)
                        client = PayPalHttpClient(environment)
                        order_request = OrdersCreateRequest()

                        order_request.prefer('return=representation')

                        order_request.request_body({
                            "intent":
                            "CAPTURE",
                            "purchase_units": [{
                                "amount": {
                                    "currency_code": "USD",
                                    "value": args['user_display_amount']
                                }
                            }],
                            "application_context": {
                                "shipping_preference": 'NO_SHIPPING'
                            }
                        })
                        try:
                            # Call API with your client and get a response for your call
                            response = client.execute(order_request)
                            if response.result and response.result.id:

                                return {
                                    'message': 'success',
                                    'data': {
                                        'orderId': response.result.id
                                    }
                                }, 200
                            else:
                                return {
                                    'message':
                                    'Error while completing payment, please retry.'
                                }, 500
                        except IOError as ioe:
                            if isinstance(ioe, HttpError):
                                # Something went wrong server-side
                                print(ioe.status_code)
                            return {
                                'message':
                                'Error while completing payment, please retry.'
                                ' If the issue still persists, try after sometime.'
                            }, 500
                    else:
                        return {
                            'message':
                            'Price changed for one or more product. Getting the latest price'
                        },
                else:
                    return {'message': 'User Auth is missing.'}, 401
            else:
                return {'message': 'Validation error, try again'}, 500

        except Exception as e:
            app.logger.debug(e)
            return {
                'message':
                'Error while completing payment, please retry.'
                ' If the issue still persists, try after sometime.'
            }, 500