Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何支持使用多个商户帐号? #27

Closed
chloerei opened this issue Mar 26, 2015 · 5 comments
Closed

如何支持使用多个商户帐号? #27

chloerei opened this issue Mar 26, 2015 · 5 comments
Milestone

Comments

@chloerei
Copy link
Owner

有时会需要使用多个帐号,例如更换商户帐号的时候,新订单支付地址使用新帐号,旧的订单在一段时间内还需要处理异步消息。

方案一:

在现有方法上扩展,每个方法可以传入参数从而使用不同的帐号。

Alipay.pid = 'acount_1'
Alipay.seller_email = 'seller_email_1'
Alipay.key = 'key_1'

Alipay::Service.create_partner_trade_by_buyer_url(out_trade_no: 1000) # 使用 account_1

Alipay::Service.create_partner_trade_by_buyer_url(
  out_trade_no: 1000,
  pid: 'account_2',
  seller_email: 'seller_email_2,
  key: 'key_2'
) # 使用 account_2

如果要使用很多商户帐号,那么不设置默认值也可以。这个方案类似于 Stripe 的接口 https://stripe.com/docs/api/ruby

这个方案优势是改动小,api 基本不变,但是代码隔离不清晰。

方案二:

更改所有接口,需要先实例化:

alipay_1 = Alipay::Service.new(
  pid: 'acount_1',
  key: 'key_1'
)

alipay_2 = Alipay::Service.new(
  pid: 'acount_2',
  key: 'key_2'
)

alipay_1.create_partner_trade_by_buyer_url(..) # 使用 account_1

alipay_2.create_partner_trade_by_buyer_url(..) # 使用 account_2

这种方式类似于 dalli, redis-rb。

这个方案优势是代码隔离清晰,对象化,缺点是 api 全部要变更。

哪个方案比较好?

@chloerei chloerei added this to the 0.6.0 milestone Mar 26, 2015
@chloerei chloerei changed the title 支持使用多个商户帐号 如何支持使用多个商户帐号 Mar 26, 2015
@chloerei chloerei changed the title 如何支持使用多个商户帐号 如何支持使用多个商户帐号? Mar 26, 2015
@zlx
Copy link

zlx commented Mar 26, 2015

第一种方案 +1, 大部分人仅使用一个账号,保证大多数人使用便捷更重要。

另外,从你描述的使用场景看,仅在于处理旧订单的异步消息时需要使用到旧的商户信息,那方案一可以尽可能减少多余工作量,且基本没有迁移成本。

@chloerei
Copy link
Owner Author

@zlx 我也偏向第一种方案。先做第一种方案看是否有不可克服的困难。

@chloerei
Copy link
Owner Author

一些进展,我发现将 key 和 params 混在一起可能会造成漏洞,这种形式的接口更好:

lipay::Service.create_partner_trade_by_buyer_url(params, opts ={}) # opts: pid, key, ...

然后看了 Stripe 源码, 也是类似这样处理,接下来我会实现这种接口。

@chloerei
Copy link
Owner Author

chloerei commented Apr 1, 2015

已实现。

@chloerei chloerei closed this as completed Apr 1, 2015
@jimhj
Copy link
Contributor

jimhj commented Apr 13, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants