不重定向就无法创建付款发票

问题描述

我想通过贝宝收款。我需要向用户发送一个链接并获得报酬。正在成功创建批准链接链接。但无法使用链接付款。我使用此链接登录,点击支付,但我被重定向到 return_url。我不想要这个,我不希望用户重定向到任何地方。你只需要从他那里拿钱,就是这样。我的项目不是网站,我没有任何可以重定向客户端的页面。帮助创建付款表格,而无需将客户重定向到其他页面。我预先感谢您对我的问题的关注,并为我的英语道歉。

我会简单地重复一遍:我们需要一个无需重定向到其他页面的付款表格。拿钱就行。请帮忙配置paypalrestsdk.Payment()的参数

import paypalrestsdk

api = paypalrestsdk.set_config(
    mode="sandBox",client_id="XXX",client_secret="XXX")

token = api.get_access_token()

print(token)

payment = paypalrestsdk.Payment({
    "intent": "sale","payer": {
        "payment_method": "paypal"},"redirect_urls": {
        "return_url": "http://localhost:3000/process","cancel_url": "http://localhost:3000/cancel"
    },"transactions": [{
        "item_list": {
            "items": [{
                "name": "item","sku": "item","price": "1.00","currency": "RUB","quantity": 1}]},"amount": {
            "total": "1.00","currency": "RUB"},"description": "This is the payment transaction description."}]})
create = payment.create()
if create:
  print("Payment created successfully")
else:
  print(payment.error)

for link in payment.links:
    if link.rel == "approval_url":
        # Convert to str to avoid Google App Engine Unicode issue
        # https://github.com/paypal/rest-api-sdk-python/pull/58
        approval_url = str(link.href)
        print("Redirect for approval: %s" % (approval_url))

我尝试不为重定向指定链接。如果它们不存在,则不会创建付款。

解决方法

首先,您使用的是已弃用的 v1/payments API 和相应的 SDK。如果您要实现网站结帐,则应改用当前的 v2/checkout/orders API 及其 SDK;这样的集成是 documented here.

但正如您所指出的,您的发票用例不是正常的网站结账。确实有一个单独的发票 API,请参阅 the invoicing integration guide

没有用于开票 API 的 SDK - 使用直接 HTTPS API 调用首先获取 oauth2 访问令牌,然后创建您的发票。