Stripe payment gateway - Проблема с подключением к веб-серверу ECLIPSE - PullRequest
0 голосов
/ 02 ноября 2018

В настоящее время я использую Eclipse для проверки оплаты полосой К сожалению, у меня нет сертификата SSL. Можно ли работать без SSL на Eclipse? потому что я продолжаю получать эту ошибку в моей консоли. Я пытался создать заряд в Stripe, но ответ API-интерфейса Stripe не выскочил. Я предполагаю, что это может быть проблема соединения между Stripe и моим сервлетом.


com.stripe.exception.ApiConnectionException: IOException during API request to Stripe (https://api.stripe.com): api.stripe.com Please check your internet connection and try again. If this problem persists,you should check Stripe's service status at https://twitter.com/stripestatus, or let us know at support@stripe.com.
    at com.stripe.net.LiveStripeResponseGetter.makeUrlConnectionRequest(LiveStripeResponseGetter.java:442)
    at com.stripe.net.LiveStripeResponseGetter.getStripeResponse(LiveStripeResponseGetter.java:580)
    at com.stripe.net.LiveStripeResponseGetter.rawRequest(LiveStripeResponseGetter.java:499)
    at com.stripe.net.LiveStripeResponseGetter.staticRequest(LiveStripeResponseGetter.java:524)
    at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:81)
    at com.stripe.net.ApiResource.request(ApiResource.java:195)
    at com.stripe.model.Customer.create(Customer.java:130)
    at com.stripe.model.Customer.create(Customer.java:122)
    at testing.Payment.doGet(Payment.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.UnknownHostException: api.stripe.com
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at com.stripe.net.LiveStripeResponseGetter.createPostConnection(LiveStripeResponseGetter.java:239)
    at com.stripe.net.LiveStripeResponseGetter.makeUrlConnectionRequest(LiveStripeResponseGetter.java:414)
    ... 32 more
com.stripe.exception.ApiConnectionException: IOException during API request to Stripe (https://api.stripe.com): api.stripe.com Please check your internet connection and try again. If this problem persists,you should check Stripe's service status at https://twitter.com/stripestatus, or let us know at support@stripe.com.
    at com.stripe.net.LiveStripeResponseGetter.makeUrlConnectionRequest(LiveStripeResponseGetter.java:442)
    at com.stripe.net.LiveStripeResponseGetter.getStripeResponse(LiveStripeResponseGetter.java:580)
    at com.stripe.net.LiveStripeResponseGetter.rawRequest(LiveStripeResponseGetter.java:499)
    at com.stripe.net.LiveStripeResponseGetter.staticRequest(LiveStripeResponseGetter.java:524)
    at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:81)
    at com.stripe.net.ApiResource.request(ApiResource.java:195)
    at com.stripe.model.Charge.create(Charge.java:372)
    at com.stripe.model.Charge.create(Charge.java:364)
    at testing.Payment.doGet(Payment.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.UnknownHostException: api.stripe.com
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at com.stripe.net.LiveStripeResponseGetter.createPostConnection(LiveStripeResponseGetter.java:239)
    at com.stripe.net.LiveStripeResponseGetter.makeUrlConnectionRequest(LiveStripeResponseGetter.java:414)
    ... 32 more 

Мой индексный файл jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Stripe Pay</title>
<script src="https://js.stripe.com/v3/"></script>
<style>
.StripeElement {
    background-color: white;
    height: 10px;
    padding: 15px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    box-shadow: 0 1px 3px 0 #e6ebf1;
    -webkit-transition: box-shadow 150ms ease;
    transition: box-shadow 150ms ease;
}

.StripeElement--focus {
    box-shadow: 0 1px 3px 0 #cfd7df;
}

.StripeElement--invalid {
    border-color: #fa755a;
}

.StripeElement--webkit-autofill {
    background-color: #fefde5 !important;
}

.container {
    background-color: #f2f2f2;
    padding: 5px 20px 15px 20px;
    border: 1px solid lightgrey;
    border-radius: 3px;
}

.col-50 {
    -ms-flex: 50%; /* IE10 */
    flex: 50%;
}

.col-75 {
    -ms-flex: 75%; /* IE10 */
    flex: 75%;
}

.col-50, .col-75 {
    padding: 0 16px;
}
</style>
</head>
<body>
<h2>Payment</h2>
        <div class="col-75">
        <div class="container">
<form action="payment" method="post" id="payment-form">
             <div class="col-50">

                Address: <br> <input type="text" name="address" id= "address" placeholder="542 W.15 Street"> 
                    <br> 
                City:<br> <input type="text" name="city" id= "city" placeholder="New York"> 
                <br>
                State:<br> <input type="text" name="state" id= "state" placeholder="New York">
                    <br>
                <div class="form-row">
                    <label for="card-element"> Credit or Debit card: </label>
                    <div id="card-element">
                        <!-- A Stripe Element will be inserted here. -->                    

                    </div>

                    <!-- Used to display Element errors. -->
                    <div id="card-errors" role="alert"></div>
                </div>

                <button>Submit Payment</button>
                <input type= "hidden" id="tokens" value="token">  
                </div>
            </form>
        </div>
    </div>
    <p> Bank number : 4242 4242 4242 4242</p>
    <script>
        (function() {


            var stripe = Stripe('pk_test_uRcaa3vdG7sfD1m0SEwT5DnO');
            var elements = stripe.elements();
            var style = {
                base : {
                    // Add your base input styles here. For example:
                    fontSize : '16px',
                    color : "#32325d",
                    fontFamily : '"Helvetica Neue", Helvetica, sans-serif',
                    fontSmoothing : 'antialiased',
                    '::placeholder' : {
                        color : '#aab7c4'
                    }
                },
                invalid : {
                    color : '#fa755a',
                    iconColor : '#fa755a'
                }
            };

            // Create an instance of the card Element.
            var card = elements.create('card', {
                style : style

            });




            // Add an instance of the card Element into the `card-element` <div>.
            card.mount('#card-element');

            card.addEventListener('change', function(event) {
                var displayError = document.getElementById('card-errors');
                if (event.error) {
                    displayError.textContent = event.error.message;
                } else {
                    displayError.textContent = '';
                }
            });     

            //Create a token to transmit card information
            var form = document.getElementById('payment-form');
            form.addEventListener('submit',function(event) {
                var address = document.getElementById("address").value;
                var city = document.getElementById("city").value;
                var state = document.getElementById("state").value;
                event.preventDefault();
                    stripe.createToken(card,{address_line1:address,address_city:city,address_state:state,}).then(function(result) {
                    if (result.error) {
                    // Inform the customer that there was an error.
                    var errorElement = document.getElementById('card-errors');
                    errorElement.textContent = result.error.message;
                    } else {
                    // Send the token to your server.
                    stripeTokenHandler(result.token);
                    }
                });
            });

            //Submit the token and the rest of your form to your server
            function stripeTokenHandler(token) {
                // Insert the token ID into the form so it gets submitted to the server
                var form = document.getElementById('payment-form');
                var hiddenInput = document.createElement('input');
                hiddenInput.setAttribute('type', 'hidden');
                hiddenInput.setAttribute('name', 'stripeToken');
                hiddenInput.setAttribute('value', token.id);
                form.appendChild(hiddenInput);

                // Submit the form
                form.submit();
                var token = token.id;
                alert("Success! Token: " + token)
            }
        })();
    </script>

</body>
</html>

Мой сервлет Charge

package testing;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import com.stripe.model.Customer;

/**
 * Servlet implementation class Payment
 */

public class Payment extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Payment() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        Stripe.apiKey = "sk_test_f9LqcocbUTzo75w4cODPmSWF";

         String token = request.getParameter("tokens");

         Map<String, Object> customerParameter = new HashMap<String, Object>();
         customerParameter.put("email", "a@gmail.com");
         try {
            Customer newCustomer = Customer.create(customerParameter);
        } catch (StripeException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        Map<String, Object> chargeParams = new HashMap<String, Object>();
        chargeParams.put("amount", 2000);
        chargeParams.put("currency", "usd");
        chargeParams.put("description", "Charge for Stripe Item");
        chargeParams.put("source", token );
        // ^ obtained with Stripe.js    


    try {
            Charge charge = Charge.create(chargeParams);

        } catch (StripeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    System.out.println(gson.toJson(token));
    response.setContentType("text/html");//setting the content type  
    PrintWriter pw=response.getWriter();//get the stream to write the data  

    //writing html in the stream  
    pw.println("<html><body>");  
    pw.println(chargeParams);  
    pw.println(gson.toJson(token)); 
    pw.println("</body></html>");  

    pw.close();//closing the stream  

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

Видимо, на панели инструментов полосы не отображалось ни одного созданного клиента, ни плата не отображалась на моем сайте. Единственной вещью, созданной в журнале разработчика Stripe, была запись токена.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...