Charge a credit card with Stripe#1556
Conversation
KevinGilmore
left a comment
There was a problem hiding this comment.
Please see comments within individual files for details on the requested changes.
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-devtools</artifactId> |
There was a problem hiding this comment.
Let's omit dev-tools from the module
| <dependency> | ||
| <groupId>com.stripe</groupId> | ||
| <artifactId>stripe-java</artifactId> | ||
| <version>4.0.0</version> |
There was a problem hiding this comment.
The latest now is 4.2.0
| th:attr='data-key=${stripePublicKey}, | ||
| data-amount=${amount}, | ||
| data-currency=${currency}' | ||
| data-name='Baldung' |
| <input type='hidden' th:value='${amount}' name='amount' /> | ||
| <label>Price:<span th:text='${amount/100}' /></label> | ||
| <!-- NOTE: data-key/data-amount/data-currency will be rendered by Thymeleaf --> | ||
| <script |
There was a problem hiding this comment.
Although it is supported elsewhere now, It's more typical to have a <script> tag in the section.
Either way, you do need a closing </script> tag instead of the shortcut <script ... />
There was a problem hiding this comment.
in which section should it be at? I could not understand.
There was a problem hiding this comment.
I meant to say that I've only seen <script> tags in the tag (sorry, I know I typed that in the comment but must have erased it before I submitted it) -- then again, I have been out of the UI side of web dev for a few years ;) so I will defer to you as to its placement.
But I am reasonably sure that you do still need the closing </script> tag -- the shorthand form will not be interpreted correctly -- I've experienced this firsthand, and everything I've read on stackoverflow and other sites claims that this is still the case today.
There was a problem hiding this comment.
do you mean inside head tag?
There was a problem hiding this comment.
it's not common to have scripts inside forms but look at their example :)
There was a problem hiding this comment.
So yes, the placement within the form tag is fine. Notice in their example the closing script tag.
There was a problem hiding this comment.
Yes the enclosing script I did it right away. Thanks. Will push when I implemented your suggestion of amount.
|
@KevinGilmore can you check now? thx |
KevinGilmore
left a comment
There was a problem hiding this comment.
See files for details.
| @@ -0,0 +1,33 @@ | |||
| package com.baeldung; | |||
There was a problem hiding this comment.
Let's move all classes to the package com.baeldung.stripe
| @Value("${STRIPE_SECRET_KEY}") | ||
| private String secretKey; | ||
|
|
||
| public void charge(ChargeRequest chargeRequest) |
There was a problem hiding this comment.
Let's return the Charge object returned by Charge.create(...)
| </head> | ||
| <body> | ||
| <div th:if='${error}' th:text='${error}' style='color: red;'></div> | ||
| <div th:unless='${error}' style='color: green;'>Success!</div> |
There was a problem hiding this comment.
Here's an idea: If you return the Charge object from the StripeService to the ChargeController, you could use some of the Charge response data to populate additional elements in the model for the result page. I don't know what's interesting to show, but you could pick something (maybe the charge id?) of interest.
What do you think?
There was a problem hiding this comment.
makes sense. I'll take a look at their response data.
Spring Boot project that includes Stripe Java library and does a charge to a credit card. BAEL-742
BAEL-742
BAEL-742
Spring Boot project that includes Stripe Java library and does a charge to a credit card.
BAEL-742