in membership-attribute-service/app/services/zuora/payment/SetPaymentCard.scala [28:53]
private def setPaymentCard(
useStripePaymentMethod: Boolean,
stripeService: StripeService,
)(accountId: AccountId, stripeCardIdentifier: String)(implicit logPrefix: LogPrefix): Future[PaymentCardUpdateResult] = {
val createCustomerFunction =
if (useStripePaymentMethod)
stripeService.createCustomerWithStripePaymentMethod(_)
else
stripeService.createCustomer(_)
(for {
customer <- createCustomerFunction(stripeCardIdentifier)
_ <- zuoraService
.createCreditCardPaymentMethod(accountId, customer, stripeService.paymentIntentsGateway)
} yield {
CardUpdateSuccess(
PaymentCard(
isReferenceTransaction = true,
cardType = Some(customer.card.`type`),
paymentCardDetails = Some(PaymentCardDetails(customer.card.last4, customer.card.exp_month, customer.card.exp_year)),
),
)
}).recover { case error: Stripe.Error =>
CardUpdateFailure(error.`type`, error.message.getOrElse(""), error.code.getOrElse("unknown"))
}
}