paypal - 促进网站用户之间的 PayPal 支付网关交易
问题描述
我正在制作一个网站,网站的用户可以在其中像 fiver、Upwork 和其他平台一样在现场相互付款。
我想为此目的使用 PayPal 支付网关。并在后端使用 Django-rest-framework。
有什么教程或文档你们可以参考我吗?
这是我尝试使用 payee 方法向 Paypal 发送请求时的代码。
class PaymentP2P(APIView):
permission_classes = ()
# authentication_classes = (SessionAuthentication, TokenAuthentication)
def post(self,request):
email_request=request.data['payee']
price_to_pay = str(request.data['price'])
payment = paypalrestsdk.Payment(self.build_request_body(email_request,price_to_pay))
print(payment)
if payment.create():
print("Payment created successfully")
else:
print(payment.error)
return Response({'paymentID':payment.id},status=200)
@staticmethod
def build_request_body(email_user="payee@email.com",price="220.00"):
"""Method to create body with a custom PAYEE (receiver)"""
return \
{
"intent": "AUTHORIZE",
"purchase_units": [
{
"amount": {
"total": price,
"currency": "USD"
},
"payee": {
"email_address": "sb-loe4o1374588@personal.example.com"
},
},
]
}
解决方案
对于一个用户支付另一个用户的电子邮件,您可以使用带有变量的PayPal Checkout : https ://developer.paypal.com/docs/checkout/integration-features/custom-payee/payee
以下是基本结账的一些前端演示模式:
- 一种调用服务器上的端点来设置和捕获交易的方法: https ://developer.paypal.com/demo/checkout/#/pattern/server
- 一个不这样做,只使用客户端js: https ://developer.paypal.com/demo/checkout/#/pattern/client
推荐阅读
- javascript - 如何在两台或多台计算机之间共享一个 HTML 元素?
- php - 在登录期间在配置中设置动态数据库 - Laravel
- sql-server - 是否可以从变量插入表?
- python - 无法使用 dictConfig 配置过滤器
- java - 如何使用机器人在 Mac 上的 Android 模拟器上自动按键?
- swift - NSTableView:第二列不应该出现
- ruby-on-rails - 如何在上传到服务器之前压缩图像
- postgresql - 在 dockerized flask + postgres 应用程序中管理 pytest 测试的任何推荐方法?
- javascript - 在 iframe 中结合 2 个 onload 命令
- php - 将数组与公共键组合以进行 MYSQL 更新