Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Last active October 28, 2022 01:47
Show Gist options
  • Save A-pZ/4bf4e8e587dc17337fcb7a1bab5cda44 to your computer and use it in GitHub Desktop.
Save A-pZ/4bf4e8e587dc17337fcb7a1bab5cda44 to your computer and use it in GitHub Desktop.
PaymentIntentの作成(オーソリとキャプチャ分離)
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