22
33
44import com .stripe .Stripe ;
5+ import com .stripe .StripeClient ;
56import com .stripe .exception .SignatureVerificationException ;
67import com .stripe .exception .StripeException ;
7- import com .stripe .model .Customer ;
88import com .stripe .model .Event ;
99import com .stripe .model .Invoice ;
10- import com .stripe .model .Refund ;
1110import com .stripe .model .Subscription ;
1211import com .stripe .model .checkout .Session ;
13- import com .stripe .net .Webhook ;
1412import com .stripe .param .CustomerUpdateParams ;
1513import com .stripe .param .RefundCreateParams ;
1614import com .stripe .param .SubscriptionCancelParams ;
3230 */
3331public class StripeApi {
3432
33+ private final StripeClient client ;
34+
3535 public StripeApi (@ NonNull String apiKey ) {
36- Stripe . apiKey = apiKey ;
36+ client = new StripeClient ( apiKey ) ;
3737 }
3838
3939 /**
@@ -70,7 +70,7 @@ public Session createCheckoutSession(
7070 String stripeCustomerId ,
7171 Long trialPeriodDays
7272 ) throws StripeException {
73- return Session .create (
73+ return client . checkout (). sessions () .create (
7474 new SessionCreateParams .Builder ()
7575 .setSuccessUrl (successUrl )
7676 .setCancelUrl (cancelUrl )
@@ -92,32 +92,32 @@ public Session createCheckoutSession(
9292 }
9393
9494 /**
95- * @see Webhook #constructEvent(String, String, String)
95+ * @see StripeClient #constructEvent(String, String, String)
9696 */
9797 @ NonNull
9898 public Event decodeWebhookPayload (
9999 @ NonNull String payload ,
100100 @ NonNull String signature ,
101101 @ NonNull String secret
102102 ) throws SignatureVerificationException {
103- return Webhook .constructEvent (payload , signature , secret );
103+ return client .constructEvent (payload , signature , secret );
104104 }
105105
106106 /**
107- * @see Subscription #retrieve(String)
107+ * @see com.stripe.service.SubscriptionService #retrieve(String)
108108 */
109109 @ NonNull
110110 public Subscription getSubscription (@ NonNull String id ) throws StripeException {
111- return Subscription .retrieve (id );
111+ return client . subscriptions () .retrieve (id );
112112 }
113113
114114 /**
115115 * Marks an uncancelled subscription to be cancelled at the end of the current billing cycle.
116116 *
117117 * @param id id of the subscription to cancel.
118118 * @throws StripeException on Stripe API errors.
119- * @see Subscription #update(SubscriptionUpdateParams)
120- * @see Subscription #cancel(SubscriptionCancelParams)
119+ * @see com.stripe.service.SubscriptionService #update(String, SubscriptionUpdateParams)
120+ * @see com.stripe.service.SubscriptionService #cancel(String, SubscriptionCancelParams)
121121 */
122122 public void cancelSubscription (@ NonNull String id ) throws StripeException {
123123 val subscription = getSubscription (id );
@@ -126,8 +126,10 @@ public void cancelSubscription(@NonNull String id) throws StripeException {
126126 }
127127
128128 if (!requireNonNullElse (subscription .getCancelAtPeriodEnd (), false )) {
129- subscription .update (
130- SubscriptionUpdateParams .builder ()
129+ client .subscriptions ()
130+ .update (
131+ id ,
132+ SubscriptionUpdateParams .builder ()
131133 .setCancelAtPeriodEnd (true )
132134 .build ());
133135 }
@@ -140,7 +142,7 @@ public void cancelSubscription(@NonNull String id) throws StripeException {
140142 * @throws StripeException on Stripe API errors.
141143 */
142144 public void refundSubscription (@ NonNull String id ) throws StripeException {
143- val subscription = Subscription .retrieve (
145+ val subscription = client . subscriptions () .retrieve (
144146 id ,
145147 SubscriptionRetrieveParams .builder ()
146148 .addExpand ("latest_invoice" )
@@ -154,7 +156,7 @@ public void refundSubscription(@NonNull String id) throws StripeException {
154156
155157 if (charge != null ) {
156158 try {
157- Refund .create (
159+ client . refunds () .create (
158160 RefundCreateParams .builder ()
159161 .setCharge (charge )
160162 .build ());
@@ -166,19 +168,19 @@ public void refundSubscription(@NonNull String id) throws StripeException {
166168 }
167169
168170 if (!"canceled" .equals (subscription .getStatus ())) {
169- subscription . cancel ();
171+ client . subscriptions (). cancel (id );
170172 }
171173 }
172174
173175 /**
174- * @see com.stripe.model .billingportal.Session #create(com.stripe.param.billingportal.SessionCreateParams)
176+ * @see com.stripe.service .billingportal.SessionService #create(com.stripe.param.billingportal.SessionCreateParams)
175177 */
176178 @ NonNull
177179 public com .stripe .model .billingportal .Session createCustomerPortalSession (
178180 @ NonNull String customerId ,
179181 String returnUrl
180182 ) throws StripeException {
181- return com . stripe . model . billingportal . Session .create (
183+ return client . billingPortal (). sessions () .create (
182184 com .stripe .param .billingportal .SessionCreateParams .builder ()
183185 .setCustomer (customerId )
184186 .setReturnUrl (returnUrl )
@@ -193,7 +195,8 @@ public com.stripe.model.billingportal.Session createCustomerPortalSession(
193195 * @throws StripeException on upstream errors.
194196 */
195197 public void resetCustomerNameAndEmail (@ NonNull String customerId ) throws StripeException {
196- Customer .retrieve (customerId ).update (
198+ client .customers ().update (
199+ customerId ,
197200 CustomerUpdateParams .builder ()
198201 .setName (EmptyParam .EMPTY )
199202 .setEmail (EmptyParam .EMPTY )
0 commit comments