Here is my code for Create a PaymentMethod API . I found this code from
https://docs.stripe.com/api/payment_methods/create
But it is giving error . need a solution for overcome this issue.
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.PaymentMethod;
import com.stripe.param.PaymentMethodCreateParams;
public class Main {
public static void main(String[] args) throws StripeException {
System.out.println("Hello world!");
Stripe.apiKey = "sk_t";
PaymentMethodCreateParams params =
PaymentMethodCreateParams.builder()
.setType(PaymentMethodCreateParams.Type.CARD)
.setCard(
PaymentMethodCreateParams.CardDetails.builder()
.setNumber("pm_card_visa")
.setExpMonth(8L)
.setExpYear(2026L)
.setCvc("314")
.build()
)
.build();
PaymentMethod paymentMethod = PaymentMethod.create(params);
System.out.println("done!");
}
}
I have found bellow error after running this code . please help why it is giving this error.
I am using this stripe version : 25.0.0
Error :
**Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing. To enable raw card data APIs in
**
Exception in thread "main" com.stripe.exception.CardException:
Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing. To enable raw card data APIs in test mode, see https://support.stripe.com/questions/enabling-access-to-raw-card-data-apis.; request-id: req_UzVH4M3J5n22oP
at com.stripe.net.LiveStripeResponseGetter.handleApiError(LiveStripeResponseGetter.java:255)
at com.stripe.net.LiveStripeResponseGetter.handleError(LiveStripeResponseGetter.java:198)
at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:102)
at com.stripe.model.PaymentMethod.create(PaymentMethod.java:405)
at com.stripe.model.PaymentMethod.create(PaymentMethod.java:379)
at com.sam.Main.main(Main.java:32)
Process finished with exit code 1