Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stripe Webhook logic to retrieve payment intent events, and add to Payment entity valid status and description #57

Merged
merged 11 commits into from
Jul 28, 2023

Conversation

Reyzis2021
Copy link
Contributor

@Reyzis2021 Reyzis2021 commented Jul 23, 2023

Changes:

  1. A complete refactoring was carried out throughout the entire payment API, the code was adapted to the architecture and requirements of the project, it was also rewritten using SOLID principles, for greater frequency and improved code readability.
  2. Added a new payment endpoint method paymentEventsProcess(/api/v1/payment/event ), as well as end to end business logic for it, edit table in liquibase, logic for processing events that are passed to us as input, repository, etc.
  3. Added java docks for classes using the Stripe API, for a better understanding of what is happening in them.
  4. Added a handler to execute different scenarios based on the type of event.
  5. Added permission to the spring security configuration for this endpoint to avoid blocking work with the stripe remotely and its resources.

Test: At the moment, we don't have stripe logic on the frontend side yet. You have to generate events yourself, using Stripe SLI. And check how events are caught, and how, based on this, this or that logic works, which is intended to be executed in response to an event. The application rises, the endpoint has been tested. I will try to describe in detail how to test this logic in the Trello ticket.

…o Payment entity valid status and description
# Conflicts:
#	src/main/java/com/zufar/onlinestore/payment/PaymentApi.java
#	src/main/java/com/zufar/onlinestore/payment/config/StripeConfiguration.java
#	src/main/java/com/zufar/onlinestore/payment/dto/PaymentDetailsDto.java
#	src/main/java/com/zufar/onlinestore/payment/dto/PaymentWithTokenDetailsDto.java
#	src/main/java/com/zufar/onlinestore/payment/processor/PaymentProcessor.java
@@ -25,15 +30,38 @@ public class Payment {
@Column(name = "payment_id")
private Long paymentId;

@Column(nullable = false, unique = true, name = "payment_intent_id")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it please

* @param stripeSignatureHeader this param it is a string describing of the stripe signature, which provide safe work with Stripe API webhooks mechanism
* @throws SignatureVerificationException this exception throw then stripe signature verification problem was occurred
* */
void paymentEventProcess(final String paymentIntentPayload, final String stripeSignatureHeader) throws SignatureVerificationException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processPaymentEvent *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


@PostConstruct
private void init() {
Stripe.apiKey = secretKey;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably remove extra space here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public ResponseEntity<Void> paymentEventsProcess(
@RequestBody @Valid @NotEmpty String paymentIntentPayload,
@RequestHeader("Stripe-Signature") @Valid @NotEmpty String stripeSignatureHeader) throws SignatureVerificationException {
if (Objects.isNull(paymentIntentPayload) || Objects.isNull(stripeSignatureHeader)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constrained with @notempty must be not null, and its size/length must be greater than zero.

I dont see so much sense to put additional if checks for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @NotNull constraint, but NotEmpty annotation validate that string must be not null, and its size/length must be greater than zero, adding @SiZe doesnt make sense

@@ -25,15 +30,38 @@ public class Payment {
@Column(name = "payment_id")
private Long paymentId;

@Column(nullable = false, unique = true, name = "payment_intent_id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+

Payment updatedPayment = paymentRepository.updateStatusAndDescriptionInPayment(
paymentIntent.getId(), status, status.getDescription());
log.info("Handle payment scenario method: finish of handling payment intent: {} by failed scenario.", paymentIntent);
log.debug("Handle payment scenario method: payment data was updated: {}.", updatedPayment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

paymentIntent.getId(), status, status.getDescription());
log.info("Handle payment scenario method: finish of handling payment intent: {} by successful scenario.", paymentIntent);
log.debug("Handle payment scenario method: payment data was updated: {}.", updatedPayment);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Sunagatov Sunagatov merged commit f85781c into Sunagatov:development Jul 28, 2023
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants