Skip to content

Commit

Permalink
Added methods to Stripe Service for retrieving and attaching payment …
Browse files Browse the repository at this point in the history
…methods.
  • Loading branch information
ericrivera228 committed Aug 3, 2019
1 parent e4c7f21 commit d24e567
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ public SetupIntent createSetupIntent(@Nullable Map<String, Object> params) {

}

/**
* Retrieves a payment method of the given ID. Throws an error if the given ID is not a valid payment method.
* @return Payment method object pulled from Stripe.
*/
public PaymentMethod retrievePaymentMethod(String paymentMethodId) {

try{
return PaymentMethod.retrieve(paymentMethodId);
} catch (StripeException e) {
throw new UncheckedStripeException(e);
}

}

/**
* Attaches the given payment method to the given customer.
* @param paymentMethod Payment method to attach to the customer
* @param stripeCustomerId Stripe ID of the customer to attach the payment method too
*/
public void attachPaymentMethodToCustomer(PaymentMethod paymentMethod, String stripeCustomerId) {

Preconditions.checkNotNull(paymentMethod);
Preconditions.checkNotNull(stripeCustomerId);

Map<String,Object> params = new HashMap<>();
params.put("customer", stripeCustomerId);

try{
paymentMethod.attach(params);
} catch (StripeException e) {
throw new UncheckedStripeException(e);
}

}


/**
* Run a one-off charge, either from a customer or a source token.
Expand Down

0 comments on commit d24e567

Please sign in to comment.