def init_api(self): if self.settings.connect_client_id and not self.settings.secret: paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.connect_endpoint else 'live', client_id=self.settings.connect_client_id, client_secret=self.settings.connect_secret_key, openid_client_id=self.settings.connect_client_id, openid_client_secret=self.settings.connect_secret_key, openid_redirect_uri=urlquote(build_global_uri('plugins:paypal:oauth.return'))) else: paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.get('endpoint') else 'live', client_id=self.settings.get('client_id'), client_secret=self.settings.get('secret'))
def init_api(self): if self.settings.connect_client_id: paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.connect_endpoint else 'live', client_id=self.settings.connect_client_id, client_secret=self.settings.connect_secret_key, openid_client_id=self.settings.connect_client_id, openid_client_secret=self.settings.connect_secret_key, openid_redirect_uri=urlquote(build_global_uri('plugins:paypal:oauth.return'))) else: paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.get('endpoint') else 'live', client_id=self.settings.get('client_id'), client_secret=self.settings.get('secret'))
def get_auth_token(cls): api = paypalrestsdk.set_config( mode=settings.SHOP_PAYPAL['MODE'], client_id=settings.SHOP_PAYPAL['CLIENT_ID'], client_secret=settings.SHOP_PAYPAL['CLIENT_SECRET']) auth_token_hash = api.get_token_hash() return auth_token_hash
def createpayment(payment_amount): global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id="AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret="EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD") access_token = api.get_access_token() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:5000/executepaymentrequest", "cancel_url": "http://localhost:5000/checkoutpage" }, "transactions": [ { "amount": { "total": payment_amount, "currency": "USD" }, "description": "creating a payment of " + str(payment_amount) } ] } ) payment_response = payment.create() if payment_response == True: return "payment created. <p>payment: " + str(payment) + "</p>Payment amount: " + str(payment_amount) + "<p>Payment redirect_url: " + str(payment['links'][1]["href"]) + "</p>" + "<p>access token = " + str(access_token) + "</p>" if payment_response == False: return "payment not created"
def getaccesstoken(): global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id="AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret="EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD") access_token = api.get_access_token() return "access token = " + str(access_token) + "<p><a href='/checkoutpage'>Checkout page</a></p>"
def createpayment(): if request.method == 'POST': if request.form["payment_amount"]: if checkCustomerOrderCookie(): customerorder = checkCustomerOrderCookie() payment_amount = request.form['payment_amount'] global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id= "AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret= "EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD" ) access_token = api.get_access_token() payment = paypalrestsdk.Payment({ "intent": "sale", "redirect_urls": { "return_url": "http://52.2.64.93:5000/executepaymentrequest", "cancel_url": "http://52.2.64.93:5000/checkout" }, "payer": { "payment_method": "paypal", "payer_info": { "shipping_address": { "line1": str(customerorder.customer_delivery_address), "country_code": "HK" } } }, "transactions": [{ "amount": { "total": payment_amount, "currency": "USD" }, "description": "creating a payment of US$" + str(payment_amount), }], }) payment_response = payment.create() if (payment_response == True) and (len(payment['links']) > 1): return render_template( "customercreatepayment.html", redirect_url=payment['links'][1]["href"]) if payment_response == False: return "payment not created" else: return "'customerordercookie' does not exist" else: return "payment_amount not passed in POST method"
def getaccesstoken(): global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id= "AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret= "EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD" ) access_token = api.get_access_token() return "access token = " + str( access_token) + "<p><a href='/checkoutpage'>Checkout page</a></p>"
def createpayment(): if request.method == "POST": if request.form["payment_amount"]: if checkCustomerOrderCookie(): customerorder = checkCustomerOrderCookie() payment_amount = request.form["payment_amount"] global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id="AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret="EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD", ) access_token = api.get_access_token() payment = paypalrestsdk.Payment( { "intent": "sale", "redirect_urls": { "return_url": "http://52.2.64.93:5000/executepaymentrequest", "cancel_url": "http://52.2.64.93:5000/checkout", }, "payer": { "payment_method": "paypal", "payer_info": { "shipping_address": { "line1": str(customerorder.customer_delivery_address), "country_code": "HK", } }, }, "transactions": [ { "amount": {"total": payment_amount, "currency": "USD"}, "description": "creating a payment of US$" + str(payment_amount), } ], } ) payment_response = payment.create() if (payment_response == True) and (len(payment["links"]) > 1): return render_template("customercreatepayment.html", redirect_url=payment["links"][1]["href"]) if payment_response == False: return "payment not created" else: return "'customerordercookie' does not exist" else: return "payment_amount not passed in POST method"
def paypal_api(): try: if settings.PAYPAL_SANDBOX_MODE: mode = 'sandbox' client_id = settings.PAYPAL_SANDBOX_CLIENT_ID client_secret = settings.PAYPAL_SANDBOX_CLIENT_SECRET else: mode = 'live' client_id = settings.PAYPAL_CLIENT_ID client_secret = settings.PAYPAL_CLIENT_SECRET except AttributeError: raise ImproperlyConfigured(_("Credenciais de acesso ao paypal estao faltando, " "isso inclui PAYPAL_SANDBOX_MODE, PAYPAL_CLIENT_ID e PAYPAL_CLIENT_SECRET " "basta inclui-las no settings.py para serem utilizadas " "no processador de pagamentos do paypal.")) api = paypalrestsdk.set_config(mode = mode, client_id = client_id, client_secret = client_secret) os.environ['PAYPAL_MODE'] = mode os.environ['PAYPAL_CLIENT_ID'] = client_id os.environ['PAYPAL_CLIENT_SECRET'] = client_secret return api
def createpayment(payment_amount): global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id= "AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret= "EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD" ) access_token = api.get_access_token() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:5000/executepaymentrequest", "cancel_url": "http://localhost:5000/checkoutpage" }, "transactions": [{ "amount": { "total": payment_amount, "currency": "USD" }, "description": "creating a payment of " + str(payment_amount) }] }) payment_response = payment.create() if payment_response == True: return "payment created. <p>payment: " + str( payment) + "</p>Payment amount: " + str( payment_amount) + "<p>Payment redirect_url: " + str( payment['links'][1]["href"] ) + "</p>" + "<p>access token = " + str(access_token) + "</p>" if payment_response == False: return "payment not created"
def paypal_api(): try: PAYPAL_CLIENT_ID = settings.PAYPAL_CLIENT_ID PAYPAL_CLIENT_SECRET = settings.PAYPAL_CLIENT_SECRET except AttributeError: raise ImproperlyConfigured(_("Credenciais de acesso ao paypal estao faltando, " "isso inclui PAYPAL_CLIENT_ID e PAYPAL_SECRET " "basta inclui-las no settings.py para serem utilizadas " "no processador de pagamentos do paypal.")) if settings.DEBUG: mode = 'sandbox' else: mode = 'live' api = paypalrestsdk.set_config( mode = mode, # sandbox or live client_id = PAYPAL_CLIENT_ID, client_secret = PAYPAL_CLIENT_SECRET ) os.environ['PAYPAL_MODE'] = mode # sandbox or live os.environ['PAYPAL_CLIENT_ID'] = PAYPAL_CLIENT_ID os.environ['PAYPAL_CLIENT_SECRET'] = PAYPAL_CLIENT_SECRET
def init_api(self): paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.get('endpoint') else 'live', client_id=self.settings.get('client_id'), client_secret=self.settings.get('secret'))
def index(): # #Create Payment Using PayPal Sample # This sample code demonstrates how you can process a # PayPal Account based Payment. # API used: /v1/payments/payment from paypalrestsdk import Payment from paypalrestsdk import set_config import logging logging.basicConfig(level=logging.INFO) set_config(mode=settings.paypal_mode, # sandbox or live client_id=settings.paypal_client_id, client_secret=settings.paypal_client_secret) # ###Payment # A Payment Resource; create one using # the above types and intent as 'sale' payment = Payment({ "intent": "sale", # ###Payer # A resource representing a Payer that funds a payment # Payment Method as 'paypal' "payer": { "payment_method": "paypal" }, # ###Redirect URLs "redirect_urls": { "return_url": "http://localhost:3000/payment/execute", "cancel_url": "http://localhost:3000/" }, # ###Transaction # A transaction defines the contract of a # payment - what is the payment for and who # is fulfilling it. "transactions": [ { # ### ItemList "item_list": { "items": [{ "name": "Test item", "sku": "001", "price": "5.00", "currency": "USD", "quantity": 2 }, { "name": "Test item 2", "sku": "002", "price": "125.70", "currency": "USD", "quantity": 3}]}, # ###Amount # Let's you specify a payment amount. "amount": { "total": "387.10", "currency": "USD" }, "description": "This is the payment transaction description." } ] } ) # Create Payment and return status if payment.create(): print("Payment[%s] created successfully"%(payment.id)) # Redirect the user to given approval url for link in payment.links: if link.method == "REDIRECT": redirect_url = link.href print("Redirect for approval: %s"%(redirect_url)) else: print("Error while creating payment:") print(payment.error)
def init_api(self): paypalrestsdk.set_config(mode="sandbox" if "sandbox" in self.settings.get('endpoint') else 'live', client_id=self.settings.get('client_id'), client_secret=self.settings.get('secret'))
from flask import * from flask.ext.login import current_user from datetime import datetime from dateutil import relativedelta from config import PAYPAL, PRICE, DWOLLA from models.user import User, Subscription, Payment from decimal import Decimal, getcontext payment = Blueprint('payment', __name__) # Setup PayPal API PAL = paypal_api.set_config(mode="sandbox", client_id=PAYPAL['client_id'], client_secret=PAYPAL['secret']) #PAL.get_token() # Setup Dwolla API DWL = DwollaGateway(DWOLLA['key'], DWOLLA['secret'], DWOLLA['redirect']) DWL.set_mode('TEST') def paypal(price, id, description): pay = paypal_api.Payment({ "intent": "sale", "redirect_urls": { "return_url": '{}/{}'.format(PAYPAL['return_url'], id),
logger = logging.getLogger("integration.paypal") try: PAYPAL_CLIENT_ID = settings.PAYPAL_CLIENT_ID PAYPAL_SECRET = settings.PAYPAL_SECRET except AttributeError: raise ImproperlyConfigured( _("Credenciais de acesso ao paypal estão faltando, " "isso inclui PAYPAL_CLIENT_ID e PAYPAL_SECRET " "basta incluí-las no settings.py para serem utilizadas " "no processador de pagamentos do paypal.")) if settings.DEBUG: mode = "sandbox" else: mode = "live" logger.debug( "Credenciais de acesso : mode = %s, client_id = %s, client_secret = %s" % (mode, PAYPAL_CLIENT_ID, PAYPAL_SECRET)) api = paypalrestsdk.set_config( mode=mode, # sandbox or live client_id=PAYPAL_CLIENT_ID, client_secret=PAYPAL_SECRET) # autenticação access_token = api.get_token() logger.debug("Paypal Access Token %s" % access_token)
# -*- coding:utf-8 -*- from __future__ import unicode_literals from django.conf import settings from paypalrestsdk import Payment import paypalrestsdk paypalrestsdk.set_config( model='sandbox', client_id=settings.PAYPAL_CLIENT_ID, client_secret=settings.PAYPAL_CLIENT_SECRET) from django.contrib import messages from django.core.urlresolvers import reverse, reverse_lazy from django.core.validators import MaxValueValidator, MinValueValidator from django.forms.models import modelform_factory from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.views.generic import (CreateView, DetailView, ListView, RedirectView, UpdateView) from main.models import Company, FAQCategory, Transaction class CSVResponseMixin(object): def render_to_response(self, context, **response_kwargs): if self.request.GET.get('response') == 'csv': first_split = self.get_template_names()[0].split('/') second_split = first_split[1].split('_') name = self.model._meta.verbose_name_plural response = HttpResponse(content_type='text/csv')
def paypalPayment(self, is_prod_server, request_id, user_email, amount, point_for_use=0, promo_type='', promo_code='', is_additional=False, is_groupRequest=False, is_public=False): """ 페이팔은 그냥 모든 정보를 URL에 박아서 페이팔에 넘겨주면 된다. 결제는 페이팔에서 한 후 콜백으로 postprocessing을 불러오기때문에, 여기서는 페이팔로의 링크만 제공해주면 된다. """ pay_by = "web" host_name = "" # SANDBOX if is_prod_server == False: host_name = "http://ciceron.xyz" paypalrestsdk.configure(mode="sandbox", client_id="my_client_id", client_secret="my_client_secret") # LIVE else: host_name = "http://ciceron.me" paypalrestsdk.set_config(mode="live", client_id="my_client_id", client_secret="my_client_real_secret") logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.ERROR) postprocess_api = "%s/%s" % ( host_name, 'api/user/requests/%d/payment/postprocess' % request_id) param_dict = { 'pay_via': 'paypal', 'status': 'success', 'user_id': user_email, 'pay_amt': amount, 'pay_by': pay_by, 'use_point': point_for_use, 'promo_type': promo_type, 'promo_code': promo_code, 'is_additional': 'false' if is_additional == False else 'true', 'is_groupRequest': 'false' if is_groupRequest == False else 'true', 'is_public': 'false' if is_public == False else 'true' } return_url = ciceron_lib.apiURLOrganizer(postprocess_api, **param_dict) param_dict['status'] = 'fail' cancel_url = ciceron_lib.apiURLOrganizer(postprocess_api, **param_dict) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "amount": { "total": "%.2f" % amount, "currency": "USD", }, "description": "Ciceron translation request fee USD: %f" % amount }] }) rs = payment.create() # return True or False paypal_link = None for item in payment.links: if item['method'] == 'REDIRECT': paypal_link = item['href'] break if bool(rs) is True: return True, paypal_link else: return False, None
def paypalPayment2(self, is_prod_server, request_id, user_email, amount, product, point_for_use=0, promo_type='', promo_code=''): """ 페이팔은 그냥 모든 정보를 URL에 박아서 페이팔에 넘겨주면 된다. 결제는 페이팔에서 한 후 콜백으로 postprocessing을 불러오기때문에, 여기서는 페이팔로의 링크만 제공해주면 된다. """ host_name = "" # SANDBOX if is_prod_server == False: host_name = "http://ciceron.xyz" paypalrestsdk.configure(mode="sandbox", client_id="my_client_id", client_secret="my_client_secret") # LIVE else: host_name = "http://ciceron.me" paypalrestsdk.set_config(mode="live", client_id="my_real_client_kd", client_secret="my_real_client_secret") logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.ERROR) postprocess_endpoint = self._organizePostprocessApiAddress( product, request_id) postprocess_api = "{}/{}".format(host_name, postprocess_endpoint) param_dict = { 'payment_platform': 'paypal', 'product': product, 'request_id': request_id, 'status': 'success', 'user_email': user_email, 'amount': amount, 'use_point': point_for_use, 'promo_type': promo_type, 'promo_code': promo_code } return_url = ciceron_lib.dictToUrlParam(postprocess_api, **param_dict) param_dict['status'] = 'fail' cancel_url = ciceron_lib.dictToUrlParam(postprocess_api, **param_dict) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "amount": { "total": "%.2f" % amount, "currency": "USD", }, "description": "Ciceron translation request fee USD: %f" % amount }] }) rs = payment.create() # return True or False paypal_link = None for item in payment.links: if item['method'] == 'REDIRECT': paypal_link = item['href'] break if bool(rs) is True: return True, paypal_link else: return False, None
logger = logging.getLogger("integration.paypal") try: PAYPAL_CLIENT_ID = settings.PAYPAL_CLIENT_ID PAYPAL_SECRET = settings.PAYPAL_SECRET except AttributeError: raise ImproperlyConfigured( _( "Credenciais de acesso ao paypal estão faltando, " "isso inclui PAYPAL_CLIENT_ID e PAYPAL_SECRET " "basta incluí-las no settings.py para serem utilizadas " "no processador de pagamentos do paypal." ) ) if settings.DEBUG: mode = "sandbox" else: mode = "live" logger.debug( "Credenciais de acesso : mode = %s, client_id = %s, client_secret = %s" % (mode, PAYPAL_CLIENT_ID, PAYPAL_SECRET) ) api = paypalrestsdk.set_config(mode=mode, client_id=PAYPAL_CLIENT_ID, client_secret=PAYPAL_SECRET) # sandbox or live # autenticação access_token = api.get_token() logger.debug("Paypal Access Token %s" % access_token)
def init_api(self): paypalrestsdk.set_config( mode="sandbox" if "sandbox" in self.settings.get("endpoint") else "live", client_id=self.settings.get("client_id"), client_secret=self.settings.get("secret"), )