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)
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)
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, }
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)
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)
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)
def pago(request): # Creating Access Token for Sandbox client_id = "AWKxRtjpmHR9Jd8n8fMGO77lqcIw7fFHML19xSzd1Scfv4Mk-XGwnjBYJIkaRaFa_y2LC2PXBulTMPFK" client_secret = "EGlVhQYGDzop2HftvmEqh726ChUjz4e7x_Ai4Hp900iA8troRX5feiS6ThlfB-HSVwzKNdHW2W3BzCyf" # Creating an environment environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret) client = PayPalHttpClient(environment) # Construct a request object and set desired parameters # Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders requestPaypal = OrdersCreateRequest() sesion_id = request.session.session_key registro = Ventas_por_enviar.objects.filter(sesion=sesion_id) posicion = (len(registro)) total = registro[posicion - 1].total total_stripe = float(total) total_stripe = total_stripe * 100 requestPaypal.prefer('return=representation') requestPaypal.request_body({ "intent": "CAPTURE", "purchase_units": [{ "amount": { "currency_code": 'MXN', "value": float(total), } }], "application_context": { "return_url": "http://127.0.0.1:8000/checkout/exitoso", "cancel_url": "http://127.0.0.1:8000/checkout/cancelado", "brand_name": "Joyapan" } }) try: # Call API with your client and get a response for your call response = client.execute(requestPaypal) if response.result.status == 'CREATED': approval_url = str(response.result.links[1].href) print(approval_url) return render(request, 'checkout/pago.html',{#aqui es donde esta el boton 'approval_url':approval_url,'STRIPE_PUBLISHABLE_KEY':settings.STRIPE_PUBLISHABLE_KEY,'total':total,'total_stripe':total_stripe, }) except IOError as ioe: print(ioe) if isinstance(ioe, HttpError): # Something went wrong server-side return render(request, 'checkout/pago_cancelado.html')
def pago_exitoso(request): # Creating Access Token for Sandbox client_id = "AWKxRtjpmHR9Jd8n8fMGO77lqcIw7fFHML19xSzd1Scfv4Mk-XGwnjBYJIkaRaFa_y2LC2PXBulTMPFK" client_secret = "EGlVhQYGDzop2HftvmEqh726ChUjz4e7x_Ai4Hp900iA8troRX5feiS6ThlfB-HSVwzKNdHW2W3BzCyf" # Creating an environment environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret) client = PayPalHttpClient(environment) ordenId = request.GET.get('token') payerId = request.GET.get('PayerID') requestPaypal = OrdersCaptureRequest(ordenId) print("RequestPaypal") print(requestPaypal) requestPaypal.prefer('return=representation') try: # Call API with your client and get a response for your call response = client.execute(requestPaypal) # If call returns body in response, you can get the deserialized version from the result attribute of the response print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") order = response.result.id sesion_id = request.session.session_key registro = Ventas_por_enviar.objects.filter(sesion=sesion_id) posicion = (len(registro)) registro[posicion - 1].autorizacion = order registro[posicion - 1].verificacion = payerId diccionario = { 'nombre': registro[posicion - 1].nombre, 'email': registro[posicion - 1].email, } registro[posicion - 1].save() envio_email_confirmacion(diccionario) except IOError as ioe: if isinstance(ioe, HttpError): # Something went wrong server-side print("Algo salio mal :c") print(ioe.status_code) print(ioe.headers) print(ioe) return render(request, 'checkout/pago_cancelado.html') else: # Something went wrong client side print(ioe) return render(request, 'checkout/pago_cancelado.html') return render(request, 'checkout/pago_exitoso.html')
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")
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)
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)
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)
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)
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)
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)
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)
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
class PayPalHandler: def __init__(self, client_id, client_secret): self.client_id = client_id self.client_secret = client_secret self.create_environment() self.create_client() def create_environment(self): ''' Create sandbox environment for PayPal ''' self.env = SandboxEnvironment( client_id=self.client_id, client_secret=self.client_secret ) def create_client(self): ''' Create the client ''' self.client = PayPalHttpClient(self.env) def capture_order(self, order_id, debug=True): request = OrdersCaptureRequest(order_id) response = self.client.execute(request) if debug: print("Status Code: ", response.status_code) print("Status: ", response.result.status) print("Order ID: ", response.result.id) print("Links: ") for link in response.result.links: print('\t{}: {}\tCall Type: {}'.format(link.rel, link.href, link.method)) print("Capture Ids:") for purchase_unit in response.result.purchase_units: for capture in purchase_unit.payments.captures: print("\t", capture.id) return self.parse_response(response) def parse_response(self, response): return { "status_code": response.status_code, "status": response.result.status, "order_id": response.result.id, "links": [ { "rel": link.rel, "href": link.href, "method": link.method } for link in response.result.links ], "reference_id": response.result.purchase_units[0].reference_id, "buyer": { "email": response.result.payer.email_address, } } def is_completed(self, response): return response["status"] == "COMPLETED"
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
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): 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): # 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)
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)
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)
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)
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)
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)
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)
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)
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)