gpt4 book ai didi

python - 布伦特里 + Python : Configure credential at transaction level rather than module

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:57 24 4
gpt4 key购买 nike

我目前正在使用 Python 与 Braintree 集成。在模块级别,我们配置我们的 API key 。来自文档:

import braintree
braintree.Configuration.configure(...)

def my_transaction():
braintree.Transaction.sale(...)

如何在方法级别配置 braintree?也就是说,如果我想为每笔交易使用不同的凭证,我怎么能在不更新全局配置的情况下这样做呢?例如:

import braintree

def my_transaction():
braintree.Transaction.sale({
'configuration': {...},
'amount': ...
})

我希望能够根据交易来源使用不同的 API key 。我还希望能够更轻松地在 Sandbox 和 Production 凭据之间切换。

我将如何完成这个?

最佳答案

我在布伦特里工作。如需更多帮助,请get in touch with our support team .

配置对象 can be instantiated :

config = braintree.Configuration(
environment=braintree.Environment.Sandbox,
merchant_id='my_merchant_id',
public_key='public_key',
private_key='private_key'
)

并传递给 Braintree gateway object :

gateway = braintree.BraintreeGateway(config)

然后你可以use to run transactions :

result = gateway.transaction.create({'amount': ...})

因此,您可以使用适当的凭据为每个事务实例化一个新网关,或者使用每组凭据保留一个网关并使用适当的一个。

关于python - 布伦特里 + Python : Configure credential at transaction level rather than module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21237863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com