Last active
October 28, 2022 01:47
-
-
Save A-pZ/4bf4e8e587dc17337fcb7a1bab5cda44 to your computer and use it in GitHub Desktop.
PaymentIntentの作成(オーソリとキャプチャ分離)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PaymentIntentTransfer | |
/** | |
* @param request 決済情報の作成に必要なパラメータを格納。決済金額や過去Stripeを利用した際のカスタマIDが入る。 | |
*/ | |
public PaymentIntent createPaymentIntent(PaymentIntentCreateRequest request) { | |
PaymentIntentCreateParams params = createPaymentIntentCreateParams(request); | |
try { | |
return PaymentIntent.create(params); | |
} catch(StripeException e) { | |
throw new PaymentRuntimeException(e); | |
} | |
} | |
private PaymentIntentCreateParams createPaymentIntentCreateParams(PaymentIntentCreateRequest request) { | |
PaymentIntentCreateParams params = PaymentIntentCreateParams.builder() | |
.setAmount(request.totalAmount().value().longValue()) // 決済金額 | |
.setCurrency("jpy") | |
.setSetupFutureUsage(PaymentIntentCreateParams.SetupFutureUsage.OFF_SESSION) | |
.addPaymentMethodType("card") | |
.setCaptureMethod(PaymentIntentCreateParams.CaptureMethod.MANUAL) | |
.setCustomer("cus_******") // もしカスタマIDがある場合は指定 | |
.build(); | |
return params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment