2

问题

我正在尝试通过服务器端 python 启动 Express Checkout 交易(我正在使用 Flask)。我正在使用标准的paypal python SDK

  • 我正在关注文档中的 Express Checkout 工作流程。Express Checkout的 PayPal文档不是很有帮助,因为它不包含任何 python 示例。

  • 根据文件,Express Checkout 交易的第一个服务器端步骤是SetExpressCheckout调用 PayPal API。

不幸的是,我不知道如何使用 python SDK 实际执行此操作。

贝宝 SDK 源代码中的示例似乎没有提供任何相关内容。


问题

如何SetExpressCheckout在 python 中发起调用以启动 Paypal Express Checkout 工作流程?

非常感谢,

4

2 回答 2

1

Express Checkout API 是经典 API 的一部分。您在此处显示的 SDK 使用的是 REST API,这有点不同,所以这就是为什么它们对您没有太大帮助的原因。

REST API 文档在此处,在顶部右侧,您可以选择 Python 作为您将看到的示例代码。该文档应该更符合该 SDK 为您所做的工作。

于 2015-03-13T07:15:00.843 回答
0

REST API 确实支持 PayPal Express Checkout。和(NVP API)对应的操作是 ,SetExpressCheckout和( REST API)。GetExpressCheckoutDetailsDoExpressCheckoutPaymentcreatefindexecute

from uuid import uuid4
from paypalrestsdk import Payment, WebProfile
from paypalrestsdk import Api as PaypalAPI

def SetExpressCheckout(client_id, client_secret, data, profile=None, sandbox=False):
    api = PaypalAPI({
            'mode': sandbox and 'sandbox' or 'live',
            'client_id': client_id,
            'client_secret': client_secret})
    if profile:
        profile['name'] = uuid4().hex
        profile['temporary'] = True
        webprofile = WebProfile(profile, api=api)
        if not webprofile.create():
            raise Exception(webprofile.error)
        data['experience_profile_id'] = webprofile.id

    payment = Payment(data, api=api)
    if not payment.create():
        raise Exception(payment.error)
    return payment

payment = SetExpressCheckout(
            client_id='...',
            client_secret='...',
            sandbox=True,
            profile={
                'presentation': {
                    'brand_name': 'My Shop',
                    'logo_image': 'https://www.shop.com/logo.png',
                    'locale_code': 'DE',
                    },
                'input_fields': {
                    'allow_note': False,
                    'no_shipping': 0,
                    'address_override': 0,
                    },
                'flow_config': {
                    'landing_page_type': 'Login',
                    },
                 },
             data={
                 'intent': 'sale',
                 'payer': {
                     'payment_method': 'paypal',
                     'payer_info': {
                         'email': 'buyer@email.com',
                         },
                      },
                  'note_to_payer': 'A note',
                  'redirect_urls': {
                      'return_url': 'https://www.shop.com/success.py',
                      'cancel_url': 'https://www.shop.com/canceled.py',
                      },
                  'transactions': [{
                      'notify_url': 'https://www.shop.com/paypal_notify.py',
                      'item_list': {
                          'items': [{
                              'name': 'Item name',
                              'description': 'Description',
                              'sku': 'SKU',
                              'price': '10.00',
                              'currency': 'EUR',
                              'quantity': 1,
                              }],
                          },
                      'amount': {
                          'total': '10.00',
                          'currency': 'EUR',
                          },
                      'description': 'Description',
                      'payment_options': {
                          'allowed_payment_method': 'INSTANT_FUNDING_SOURCE',
                          },
                      }],
                  },
             )           

for link in payment.links:
    if link.method == 'REDIRECT':
        redirect_url = link.href
        redirect_url += '&useraction=continue' #'&useraction=commit'
        break
于 2016-12-27T20:45:40.370 回答