本文整理匯總了Python中wepay.WePay.call方法的典型用法代碼示例。如果您正苦於以下問題:Python WePay.call方法的具體用法?Python WePay.call怎麽用?Python WePay.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wepay.WePay
的用法示例。
在下文中一共展示了WePay.call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def post(self, request, *args, **kwargs):
access_token = 'STAGE_25361b68e606cc342a7e4ec982fac2139f9f72dd42156237da9468c832f56dce'
production = False
client_id = 167754
client_secret = "da07303f7e"
email = self.request.user.email
first_name = self.request.user.name
last_name = "WeParty"
wepay = WePay(production, access_token)
response = wepay.call('/user/register', {
"client_id":client_id,
"client_secret":client_secret,
"email":email,
"scope":"manage_accounts,view_balance,collect_payments,view_user",
"first_name":first_name,
"last_name":last_name,
"original_ip":"74.125.224.84",
"original_device":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.102 Safari/534.13"
})
print type(response)
print response
user_access_token = response[u'access_token']
wepay2 = WePay(production, user_access_token)
response2 = wepay.call('/account/create', {
"name": first_name + " WeParty",
"description": "WeParty account"
})
print response2
user = User.objects.get(id=request.user.id)
user.wepayUserId = response[u'user_id']
user.wepayAccountId = response2[u'account_id']
user.wepayAccessToken = response[u'access_token']
user.save()
return HttpResponseRedirect('/dashboard/')
示例2: test_default_timeout_is_passed_to_requests
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def test_default_timeout_is_passed_to_requests():
api = WePay()
api.requests = Mock()
api.call('/some_uri')
eq_([call('https://wepayapi.com/v2/some_uri',
headers={'Content-Type': 'application/json',
'User-Agent': 'WePay Python SDK'},
data=None, timeout=30)],
api.requests.post.call_args_list)
示例3: create_checkout
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def create_checkout(self, redirect_uri):
"""
Performs WePay checkout/create API call request.
Returns checkout_uri to create checkout form.
"""
production = settings.WEPAY['in_production']
access_token = self.wepay_access_token
wepay = WePay(production, access_token)
name = self.user.first_name + " " + self.user.last_name
desc = "Purchasing " + self.produce + " from " + name
price = str(self.produce_price)
account_id = str(self.get_account_id())
app_fee = str(Decimal('0.1') * self.produce_price)
params = {
'account_id': account_id,
'short_description': desc,
'type': 'GOODS',
'app_fee': app_fee,
'amount': price,
'mode': 'iframe'
}
try:
create_response = wepay.call('/checkout/create', params)
checkout_uri = create_response['checkout_uri']
return True, checkout_uri
except WePayError as e:
return False, e
示例4: wepay_membership_response
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def wepay_membership_response(user):
"""
Make a WePay API call for membership payment and return the response.
"""
# Generate verification_key for wepay payment.
random_string = base64.urlsafe_b64encode(os.urandom(30))
verification_key = hashlib.sha224(random_string + user.email +
user.name).hexdigest()
user.wepay_verification = verification_key
db.session.commit()
# WePay Application settings
account_id = app.config['WEPAY_ACCT_ID']
access_token = app.config['WEPAY_ACC_TOK']
production = app.config['WEPAY_IN_PROD']
wepay = WePay(production, access_token)
redirect_url = app.config['HOST_URL'] + '/verify/' + verification_key
response = wepay.call('/checkout/create', {
'account_id': account_id,
'amount': '20.00',
'short_description': '1 year ACM Club Membership',
'mode': 'regular',
'type': 'SERVICE',
'redirect_uri': redirect_url
})
return response
示例5: wepay_membership_response
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def wepay_membership_response(user):
"""
Make a WePay API call for membership payment and return the response.
"""
random_string = base64.urlsafe_b64encode(os.urandom(30))
verification_key = hashlib.sha224(random_string + user.email +
user.name).hexdigest()
user.wepay_verification = verification_key
db.session.commit()
# Application settings
account_id = 319493
access_token = '6dd6802f8ebef4992308a0e4f7698c275781ac36854f9451127115d995d8cda7'
production = False
wepay = WePay(production, access_token)
redirect_url = 'http://acm.frvl.us:5000/verify/' + verification_key
response = wepay.call('/checkout/create', {
'account_id': account_id,
'amount': '20.00',
'short_description': '1 year ACM Club Membership',
'mode': 'regular',
'type': 'SERVICE',
'redirect_uri': redirect_url
})
return response
示例6: GET
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def GET(self, query):
wepay = WePay(IN_PRODUCTION)
code = web.input(code='')['code']
try:
# try to get a token with our code
wepay.get_token(web.ctx.homedomain + '/callback', CLIENT_ID, CLIENT_SECRET, code)
# make a new account
create_response = wepay.call('/account/create', { 'name': 'kitty expenses fund', 'description': 'all the money for my kitty' })
# give the account a new picture
wepay.call('/account/modify', { 'account_id': create_response['account_id'], 'image_uri': 'http://www.placekitten.com/500/500' })
# redirect to the new account
web.redirect(create_response['account_uri'])
except WePay.WePayError as e:
return "Received a WePay Error: " + repr(e)
示例7: create_wepay_account
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def create_wepay_account(access_token):
# set production to True for live environments
production = settings.WEPAY_PRODUCTION
# Use access token to create account for a user.
wepay = WePay(production, access_token)
response = wepay.call('/account/create', {
'name': 'CrowdEmpowered Project Contribution',
'description': 'Crowdfunding Platform'
})
return response
示例8: GET
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def GET(self, query):
wepay = WePay(IN_PRODUCTION)
code = web.input(code="")["code"]
try:
# try to get a token with our code
wepay.get_token(web.ctx.homedomain + "/callback", CLIENT_ID, CLIENT_SECRET, code)
# make a new account
create_response = wepay.call(
"/account/create", {"name": "kitty expenses fund", "description": "all the money for my kitty"}
)
# give the account a new picture
wepay.call(
"/account/modify",
{"account_id": create_response["account_id"], "image_uri": "http://www.placekitten.com/500/500"},
)
# redirect to the new account
web.redirect(create_response["account_uri"])
except WePay.WePayError as e:
return "Received a WePay Error: " + repr(e)
示例9: get
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def get(self, request, *args, **kwargs):
if self.request.GET.get('checkout_id'):
wepay = WePay(settings.WEPAY_IN_PRODUCTION, settings.WEPAY_ACCESS_TOKEN)
wepay_data = wepay.call('/checkout/', {
'checkout_id': self.request.GET.get('checkout_id'),
})
for obj in serializers.deserialize("xml", wepay_data['long_description'], ignorenonexistent=True):
obj.object.created = datetime.datetime.now()
obj.object.checkout_id = self.request.GET.get('checkout_id')
obj.save()
action.send(self.request.user, verb='placed a $' + str(obj.object.price) + ' bounty on ', target=obj.object.issue)
post_to_slack(obj.object)
return super(IssueDetailView, self).get(request, *args, **kwargs)
示例10: get
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
except Http404:
messages.error(self.request, 'That issue was not found.')
return redirect("/")
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
if self.request.GET.get('paymentId'):
import paypalrestsdk
paypalrestsdk.configure({
'mode': settings.MODE,
'client_id': settings.CLIENT_ID,
'client_secret': settings.CLIENT_SECRET
})
payment = paypalrestsdk.Payment.find(self.request.GET.get('paymentId'))
custom = payment.transactions[0].custom
if payment.execute({"payer_id": self.request.GET.get('PayerID')}):
for obj in serializers.deserialize("json", custom, ignorenonexistent=True):
obj.object.created = datetime.datetime.now()
obj.object.checkout_id = self.request.GET.get('checkout_id')
obj.save()
action.send(self.request.user, verb='placed a $' + str(obj.object.price) + ' bounty on ', target=obj.object.issue)
post_to_slack(obj.object)
if not settings.DEBUG:
create_comment(obj.object.issue)
else:
messages.error(request, payment.error)
if self.request.GET.get('checkout_id'):
wepay = WePay(settings.WEPAY_IN_PRODUCTION, settings.WEPAY_ACCESS_TOKEN)
wepay_data = wepay.call('/checkout/', {
'checkout_id': self.request.GET.get('checkout_id'),
})
for obj in serializers.deserialize("xml", wepay_data['long_description'], ignorenonexistent=True):
obj.object.created = datetime.datetime.now()
obj.object.checkout_id = self.request.GET.get('checkout_id')
obj.save()
action.send(self.request.user, verb='placed a $' + str(obj.object.price) + ' bounty on ', target=obj.object.issue)
post_to_slack(obj.object)
if not settings.DEBUG:
create_comment(obj.object.issue)
return super(IssueDetailView, self).get(request, *args, **kwargs)
示例11: periodic
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def periodic():
global wake_time, checkout_uri
if wake_time and wake_time < time.time():
print "Trigger capture."
wake_time = None
wepay = WePay(IN_PRODUCTION, ACCESS_TOKEN)
response = wepay.call('/checkout/create', {
'account_id': ACCOUNT_ID,
'amount': saved_data['amount'],
'short_description': saved_data['desc'],
'type': 'GOODS',
'preapproval_id': preapproval_id
})
checkout_uri = response['checkout_uri']
示例12: create_account
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def create_account(self):
"""
Create a WePay account to deposit any money for produce.
"""
name = self.user.first_name + ' ' + self.user.last_name
desc = name + ' account'
production = settings.WEPAY['in_production']
access_token = self.wepay_access_token
wepay = WePay(production, access_token)
try:
create_response = wepay.call('/account/create',
{'name': name, 'description': desc})
self.wepay_account_id = create_response['account_id']
self.save()
return True, create_response
except WePayError as e:
return False, e
示例13: WePayGateway
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
class WePayGateway(Gateway):
display_name = "WePay"
homepage_url = "https://www.wepay.com/"
default_currency = "USD"
supported_countries = ["US"]
supported_cardtypes = [Visa, MasterCard]
def __init__(self):
merchant_settings = getattr(settings, "MERCHANT_SETTINGS")
if not merchant_settings or not merchant_settings.get("we_pay"):
raise GatewayNotConfigured("The '%s' gateway is not correctly "
"configured." % self.display_name)
super(WePayGateway, self).__init__()
production = not self.test_mode
self.we_pay = WePay(production)
self.we_pay_settings = merchant_settings["we_pay"]
def purchase(self, money, credit_card, options = None):
options = options or {}
params = {}
params.update({
'account_id': self.we_pay_settings.get("ACCOUNT_ID", ""),
'short_description': options.pop("description", ""),
'amount': money,
})
params.update(options)
if credit_card and not isinstance(credit_card, CreditCard):
params["payment_method_id"] = credit_card
params["payment_method_type"] = "credit_card"
token = options.pop("access_token", self.we_pay_settings["ACCESS_TOKEN"])
try:
response = self.we_pay.call('/checkout/create', params, token=token)
except WePayError, error:
transaction_was_unsuccessful.send(sender=self,
type="purchase",
response=error)
return {'status': 'FAILURE', 'response': error}
transaction_was_successful.send(sender=self,
type="purchase",
response=response)
return {'status': 'SUCCESS', 'response': response}
示例14: post
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def post(self):
global sleep_time
saved_data.update(json.loads(self.request.body))
wepay = WePay(IN_PRODUCTION, ACCESS_TOKEN)
response = wepay.call('/preapproval/create', {
'account_id': ACCOUNT_ID,
'period': 'once',
'amount': saved_data['amount'],
'mode': 'regular',
'short_description': saved_data['desc'],
'redirect_uri': 'http://54.84.158.190:8888/success'
})
sleep_time = int(saved_data['time'])
preapproval_id = response['preapproval_id']
d = response
ret = json.dumps({
'url' : d['preapproval_uri']
})
self.write(ret)
示例15: wepay_checkout
# 需要導入模塊: from wepay import WePay [as 別名]
# 或者: from wepay.WePay import call [as 別名]
def wepay_checkout(access_token, account_id, amount, campaign_title,redirect_uri=None):
# = settings.WEPAY_DONATION_SUCCESS_REDIRECT_URI
# set production to True for live environments
production = settings.WEPAY_PRODUCTION
wepay = WePay(production, access_token)
parameters = {
'account_id': account_id,
'amount': amount,
'short_description': 'Contribution to CrowdEmpowered\'s {}'.format(campaign_title),
'type': 'donation',
'currency': 'USD',
'hosted_checkout': {
"mode": "iframe"
},
}
# Wepay won't redirect to localhost so we check for that here
# in case we are running the project on localhost
if redirect_uri is not None and "localhost" not in redirect_uri:
parameters['callback_uri'] = redirect_uri
response = wepay.call('/checkout/create', parameters)
return response