如何使条纹支付实现起作用?

huangapple go评论113阅读模式
英文:

How to make stripe payments implementation works?

问题

以下是您提供的代码的翻译部分:

  1. public void chrage(HttpServletRequest request, HttpServletResponse response)
  2. {
  3. try {
  4. Stripe.apiKey = "pk_test_51He5QLAnfgVAb3ehd0OxqrNHlQSrX6MApLFlchIXfrOby4JrDwndkI76CC5QGT96y5sjbT301oj2RiC9utOgH7so00GGAJaU3d";
  5. // Token is created using Stripe Checkout or Elements!
  6. // Get the payment token ID submitted by the form:
  7. String token = request.getParameter("stripeToken");
  8. ChargeCreateParams params =
  9. ChargeCreateParams.builder()
  10. .setAmount(999L)
  11. .setCurrency("usd")
  12. .setDescription("Example charge")
  13. .setSource(token)
  14. .build();
  15. Charge charge = Charge.create(params.toMap());
  16. } catch (AuthenticationException ex) {
  17. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  18. } catch (InvalidRequestException ex) {
  19. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  20. } catch (APIConnectionException ex) {
  21. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  22. } catch (CardException ex) {
  23. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  24. } catch (APIException ex) {
  25. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  26. }
  27. }
  1. <div ng-controller="Controller" class="right_col controlador">
  2. <form id = "frmCaptura" data-toggle="validator">
  3. <div class="x_panel">
  4. <div class="x_title">
  5. <jopen:getLabel label="facturacion.nombre"/>
  6. </div>
  7. <div class="x_content">
  8. <script src="https://js.stripe.com/v3/"></script>
  9. <form action="/charge" method="post" id="payment-form">
  10. <div class="form-row">
  11. <label for="card-element">
  12. Credit or debit card
  13. </label>
  14. <div id="card-element">
  15. <!-- A Stripe Element will be inserted here. -->
  16. </div>
  17. <!-- Used to display Element errors. -->
  18. <div id="card-errors" role="alert"></div>
  19. </div>
  20. <button>Submit Payment</button>
  21. </form>
  22. </div>
  23. </div>
  24. </form>
  25. </div>

请注意,上面的翻译中只包含您提供的代码部分,不包含其他内容。如果您还有其他需要翻译的内容或有任何问题,请随时提问。

英文:

I've been trying to implement Stripe with java for testing, but my doubts are step 5 "Create Charge with the token", link for more info.
https://stripe.com/docs/payments/accept-a-payment-charges

this is my code:

java controller

  1. public void chrage(HttpServletRequest request, HttpServletResponse response)
  2. {
  3. try {
  4. Stripe.apiKey = &quot;pk_test_51He5QLAnfgVAb3ehd0OxqrNHlQSrX6MApLFlchIXfrOby4JrDwndkI76CC5QGT96y5sjbT301oj2RiC9utOgH7so00GGAJaU3d&quot;;
  5. // Token is created using Stripe Checkout or Elements!
  6. // Get the payment token ID submitted by the form:
  7. String token = request.getParameter(&quot;stripeToken&quot;);
  8. ChargeCreateParams params =
  9. ChargeCreateParams.builder()
  10. .setAmount(999L)
  11. .setCurrency(&quot;usd&quot;)
  12. .setDescription(&quot;Example charge&quot;)
  13. .setSource(token)
  14. .build();
  15. Charge charge = Charge.create(params.toMap());
  16. } catch (AuthenticationException ex) {
  17. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  18. } catch (InvalidRequestException ex) {
  19. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  20. } catch (APIConnectionException ex) {
  21. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  22. } catch (CardException ex) {
  23. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  24. } catch (APIException ex) {
  25. Logger.getLogger(FacturacionControlador.class.getName()).log(Level.SEVERE, null, ex);
  26. }
  27. }

jsp

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. &lt;script type=&quot;text/javascript&quot; src=&quot;https://js.stripe.com/v3/&quot;&gt;
  2. var stripe = Stripe(&#39;pk_test_51He5QLAnfgVAb3ehd0OxqrNHlQSrX6MApLFlchIXfrOby4JrDwndkI76CC5QGT96y5sjbT301oj2RiC9utOgH7so00GGAJaU3d&#39;);
  3. var elements = stripe.elements();
  4. var style = {
  5. base: {
  6. fontSize: &#39;16px&#39;,
  7. color: &#39;#32325d&#39;
  8. }
  9. };
  10. var card = elements.create(&#39;card&#39;, {style: style});
  11. card.mount(&#39;#card-element&#39;);
  12. var form = document.getElementById(&#39;payment-form&#39;);
  13. form.addEventListener(&#39;submit&#39;, function(event) {
  14. event.preventDefault();
  15. stripe.createToken(card).then(function (result) {
  16. if (result.error) {
  17. var errorElement = document.getElementById(&#39;card-errors&#39;);
  18. errorElement.textContent = result.error.message;
  19. } else {
  20. stripeTokenHandler(result.token);
  21. }
  22. });
  23. });
  24. function stripeTokenHandler(token) {
  25. var form = document.getElementById(&#39;payment-form&#39;);
  26. var hiddenInput = document.createElement(&#39;input&#39;);
  27. hiddenInput.setAttribute(&#39;type&#39;, &#39;hidden&#39;);
  28. hiddenInput.setAttribute(&#39;name&#39;, &#39;stripeToken&#39;);
  29. hiddenInput.setAttribute(&#39;value&#39;, token.id);
  30. form.appendChild(hiddenInput);
  31. form.submit();
  32. }
  33. &lt;/script&gt;

<!-- language: lang-css -->

  1. &lt;style type=&quot;text/css&quot;&gt;
  2. StripeElement {
  3. box-sizing: border-box;
  4. height: 40px;
  5. padding: 10px 12px;
  6. border: 1px solid transparent;
  7. border-radius: 4px;
  8. background-color: white;
  9. box-shadow: 0 1px 3px 0 #e6ebf1;
  10. -webkit-transition: box-shadow 150ms ease;
  11. transition: box-shadow 150ms ease;
  12. }
  13. .StripeElement--focus {
  14. box-shadow: 0 1px 3px 0 #cfd7df;
  15. }
  16. .StripeElement--invalid {
  17. border-color: #fa755a;
  18. }
  19. .StripeElement--webkit-autofill {
  20. background-color: #fefde5 !important;
  21. }
  22. &lt;/style&gt;

<!-- language: lang-html -->

  1. &lt;div ng-controller=&quot;Controller&quot; class=&quot;right_col controlador&quot;&gt;
  2. &lt;form id = &quot;frmCaptura&quot; data-toggle=&quot;validator&quot;&gt;
  3. &lt;div class=&quot;x_panel&quot; &gt;
  4. &lt;div class=&quot;x_title&quot;&gt;
  5. &lt;jopen:getLabel label=&quot;facturacion.nombre&quot;/&gt;
  6. &lt;/div&gt;
  7. &lt;div class=&quot;x_content&quot;&gt;
  8. &lt;script src=&quot;https://js.stripe.com/v3/&quot;&gt;&lt;/script&gt;
  9. &lt;form action=&quot;/charge&quot; method=&quot;post&quot; id=&quot;payment-form&quot;&gt;
  10. &lt;div class=&quot;form-row&quot;&gt;
  11. &lt;label for=&quot;card-element&quot;&gt;
  12. Credit or debit card
  13. &lt;/label&gt;
  14. &lt;div id=&quot;card-element&quot;&gt;
  15. &lt;!-- A Stripe Element will be inserted here. --&gt;
  16. &lt;/div&gt;
  17. &lt;!-- Used to display Element errors. --&gt;
  18. &lt;div id=&quot;card-errors&quot; role=&quot;alert&quot;&gt;&lt;/div&gt;
  19. &lt;/div&gt;
  20. &lt;button&gt;Submit Payment&lt;/button&gt;
  21. &lt;/form&gt;
  22. &lt;/div&gt;
  23. &lt;/div&gt;
  24. &lt;/div&gt;

<!-- end snippet -->

Could someone tell me what else is needed to make it work? I'd be really grateful

答案1

得分: 0

你似乎在服务器端代码中使用了一个可发布的密钥,这是行不通的 - 你需要在那里使用一个秘密密钥。

另外,你可能想考虑使用更新的支付意向方法,因为收款不支持全面的SCA。

英文:

You appear to be using a Publishable Key in your server-side code which won't work - you need to use a Secret Key there.

Also you may want to consider using the newer Payment Intents approach instead since Charges don't support SCA at all.

huangapple
  • 本文由 发表于 2020年10月23日 07:39:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64491956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定