【问题标题】:Stripe Connect API Update PaymentIntentStripe Connect API 更新 PaymentIntent
【发布时间】:2019-11-20 15:11:54
【问题描述】:

我在我的 API 中使用条带连接,我想更新现有的 paymentIntent。 API 的官方库提供了这些方法。

public PaymentIntent Get(string paymentIntentId, 
    PaymentIntentGetOptions options = null, RequestOptions requestOptions = null)
public PaymentIntent Update(string paymentIntentId, 
    PaymentIntentUpdateOptions options, RequestOptions requestOptions = null);

我唯一想更新资源的是目的地,所以我在意识到没有简单的方法之前就开始这样做了:

var paymentIntentService = new PaymentIntentService();
var paymentIntent = paymentIntentService.Get(transaction.ExternalTransactionId);

if (null != destinationStripeAccount)
{
    paymentIntent.TransferData.DestinationId = destinationStripeAccount.AccountId;
}

//This takes in a PaymentIntentUpdateOptions instead of a paymentIntent WTF
paymentIntentService.Update(paymentIntent.Id, new PaymentIntentUpdateOptions {  });

PaymentIntent 不是 PaymentIntentUpdate 选项,因此我需要将所有值映射到另一个。我宁愿不需要安装像 AutoMapper 这样的附加依赖项,手动映射字段会很麻烦。

有谁知道是否有一种方法可以只更新目的地,或者有一种简单的方法来更新付款意图?

【问题讨论】:

  • 不只需要在更新选项对象中提供需要更改的内容吗?
  • 我看看能不能找到那个对象的源代码并确认

标签: c# stripe-payments


【解决方案1】:

由于根据文档,大多数成员都是可选的,我相信您只需将需要更改/更新的内容提供给 options 对象。

var paymentIntentService = new PaymentIntentService();
var paymentIntent = paymentIntentService.Get(transaction.ExternalTransactionId);

if (null != destinationStripeAccount) {
    var options = new PaymentIntentUpdateOptions() {
        TransferData = new PaymentIntentTransferDataOptions {
            Destination = destinationStripeAccount.AccountId
        }
    };
    paymentIntentService.Update(paymentIntent.Id, options);
}

参考PaymentIntentUpdateOptions.TransferData (GitHub)

【讨论】:

  • 嗯,有趣的是,我没有想到当模型是可选的时行为会如何。我只是假设它们是可选的,如果省略该字段,则状态将被清除。我需要调查
  • 我已经与条纹团队确认是这种情况。我对他们如何处理您明确希望将可选值设为空的情况感到有些困惑,但这使我的代码更简单
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 2021-02-04
  • 2019-08-17
  • 1970-01-01
  • 2019-09-26
  • 1970-01-01
  • 2022-01-18
相关资源
最近更新 更多