Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.funixproductions.api.payment.paypal.client.clients;

import com.funixproductions.api.payment.paypal.client.dtos.responses.PaypalPlanDTO;
import com.funixproductions.core.crud.dtos.PageDTO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

/**
* Client pour gérer les plans d'abonnements Paypal.
*/
public interface PaypalPlanClient {

/**
* Crée un abonnement mensuel sur Paypal.
* @param paypalPlanDTO Dto pour créer un abonnement mensuel sur Paypal
* @return le plan créé (201 Http)
*/
@PostMapping
PaypalPlanDTO create(@RequestBody @Valid PaypalPlanDTO paypalPlanDTO);

/**
* Récupère un plan par son id.
* @param id id du plan (id de paypal)
* @return le plan (200 Http)
*/
@GetMapping("{id}")
PaypalPlanDTO getPlanById(@PathVariable @Valid @NotBlank String id);

/**
* Met à jour un plan.
* @param id id du plan (id de paypal)
* @param paypalPlanDTO Dto pour mettre à jour un plan
*/
@PatchMapping("{id}")
PaypalPlanDTO updatePlan(@PathVariable String id, @RequestBody @Valid PaypalPlanDTO paypalPlanDTO);

/**
* Active un plan, par ID.
* @param id id du plan (id de paypal)
*/
@PostMapping("{id}/activate")
PaypalPlanDTO activatePlan(@PathVariable @Valid @NotBlank String id);

/**
* Deactivates a plan, by ID.
* @param id the plan ID (PayPal ID)
*/
@PostMapping("{id}/deactivate")
PaypalPlanDTO deactivatePlan(@PathVariable @Valid @NotBlank String id);

@PostMapping("{id}/update-price")
PaypalPlanDTO updatePricePlan(
@PathVariable String id,
@RequestBody @Valid @NotNull(message = "Le prix du produit est obligatoire") @Min(value = 1, message = "Le prix du produit doit être supérieur à 1") Double newPrice
);

@GetMapping
PageDTO<PaypalPlanDTO> getAll(
@RequestParam(value = "page",defaultValue = "0") String page,
@RequestParam(value = "elemsPerPage",defaultValue = "300") String elemsPerPage,
@RequestParam(value = "search",defaultValue = "") String search,
@RequestParam(value = "sort",defaultValue = "") String sort
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.funixproductions.api.payment.paypal.client.clients;

import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(
name = "FunixProductionsPaypalPlanFeignClient",
url = "http://payment-paypal",
path = "/paypal/plans"
)
public interface PaypalPlanFeignClient extends PaypalPlanClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.funixproductions.api.payment.paypal.client.clients;

import com.funixproductions.api.payment.paypal.client.dtos.requests.paypal.PaypalCreateSubscriptionDTO;
import com.funixproductions.api.payment.paypal.client.dtos.responses.PaypalSubscriptionDTO;
import com.funixproductions.core.crud.dtos.PageDTO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
* Client pour gérer les abonnements des utilisateurs sur Paypal.
*/
public interface PaypalSubscriptionClient {

@PostMapping
PaypalSubscriptionDTO subscribe(@NotNull @Valid PaypalCreateSubscriptionDTO request);

@GetMapping("{id}")
PaypalSubscriptionDTO getSubscriptionById(@PathVariable @Valid @NotBlank String id);

@PostMapping("{id}/pause")
PaypalSubscriptionDTO pauseSubscription(@PathVariable @Valid @NotBlank String id);

@PostMapping("{id}/activate")
PaypalSubscriptionDTO activateSubscription(@PathVariable @Valid @NotBlank String id);

@PostMapping("{id}/cancel")
void cancelSubscription(@PathVariable @Valid @NotBlank String id);

@GetMapping
PageDTO<PaypalSubscriptionDTO> getAll(
@RequestParam(value = "page",defaultValue = "0") String page,
@RequestParam(value = "elemsPerPage",defaultValue = "300") String elemsPerPage,
@RequestParam(value = "search",defaultValue = "") String search,
@RequestParam(value = "sort",defaultValue = "") String sort
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.funixproductions.api.payment.paypal.client.clients;

import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(
name = "FunixProductionsPaypalSubscriptionFeignClient",
url = "http://payment-paypal",
path = "/paypal/subscriptions"
)
public interface PaypalSubscriptionFeignClient extends PaypalSubscriptionClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.funixproductions.api.payment.paypal.client.dtos.requests.paypal;

import com.funixproductions.api.payment.paypal.client.dtos.responses.PaypalPlanDTO;
import com.funixproductions.core.tools.pdf.tools.VATInformation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PaypalCreateSubscriptionDTO {

@NotNull(message = "Le plan est obligatoire")
private PaypalPlanDTO plan;

@NotNull(message = "L'utilisateur id est obligatoire")
private UUID funixProdUserId;

/**
* LA TVA, null si pas de TVA
*/
@Nullable
private VATInformation vatInformation;

@NotBlank(message = "L'URL d'annulation est obligatoire")
private String cancelUrl;

@NotBlank(message = "L'URL de retour valide est obligatoire")
private String returnUrl;

@NotBlank(message = "La marque est obligatoire")
private String brandName;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.funixproductions.api.payment.paypal.client.dtos.responses;

import com.funixproductions.core.crud.dtos.ApiDTO;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* Dto pour créer un abonnement mensuel sur Paypal.
* <a href="https://developer.paypal.com/docs/api/catalog-products/v1/#products_create">Create Product</a>
* <a href="https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create">Create plan</a>
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PaypalPlanDTO extends ApiDTO {

/**
* The plan id de paypal
*/
private String planId;

/**
* The subscription name.
*/
@NotBlank(message = "Le nom du produit est obligatoire")
@Min(value = 1, message = "Le nom du produit doit contenir au moins 1 caractère")
@Max(value = 127, message = "Le nom du produit doit contenir au maximum 127 caractères")
private String name;

/**
* The subscription description
*/
@NotBlank(message = "La description du produit est obligatoire")
@Min(value = 1, message = "La description du produit doit contenir au moins 1 caractère")
@Max(value = 256, message = "La description du produit doit contenir au maximum 256 caractères")
private String description;

/**
* The image URL for the product.
*/
@NotBlank(message = "L'URL de l'image du produit est obligatoire")
@Min(value = 1, message = "L'URL de l'image du produit doit contenir au moins 1 caractère")
@Max(value = 2000, message = "L'URL de l'image du produit doit contenir au maximum 2000 caractères")
private String imageUrl;

/**
* The home page URL for the product.
*/
@NotBlank(message = "L'URL de la page d'accueil du produit est obligatoire")
@Min(value = 1, message = "L'URL de la page d'accueil du produit doit contenir au moins 1 caractère")
@Max(value = 2000, message = "L'URL de la page d'accueil du produit doit contenir au maximum 2000 caractères")
private String homeUrl;

/**
* The subscription price. HT Hors taxes
*/
@NotNull(message = "Le prix du produit est obligatoire")
@Min(value = 1, message = "Le prix du produit doit être supérieur à 1")
private Double price;

/**
* Le nom du projet auquel est associé le plan, exemple pacifista pour un pacifista+
*/
@NotNull(message = "Le nom du projet est obligatoire")
@Min(value = 1, message = "Le nom du projet doit contenir au moins 1 caractère")
@Max(value = 50, message = "Le nom du projet doit contenir au maximum 50 caractères")
private String projectName;

public PaypalPlanDTO(String name, String description, String imageUrl, String homeUrl, Double price) {
this.name = name;
this.description = description;
this.imageUrl = imageUrl;
this.homeUrl = homeUrl;
this.price = price;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.funixproductions.api.payment.paypal.client.dtos.responses;

import com.funixproductions.core.crud.dtos.ApiDTO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;
import java.util.UUID;

/**
* <a href="https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create">Création d'un sub</a>
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PaypalSubscriptionDTO extends ApiDTO {

/**
* Le plan, pour lequel l'abonnement est créé. Doit au moins contenir l'id et le planId du plan pour la création.
*/
private PaypalPlanDTO plan;

/**
* L'id utilisateur de la funixproductions
*/
private UUID funixProdUserId;

/**
* Si l'abonnement est actif ou non. (pause ou pas)
*/
private Boolean active;

/**
* La date du dernier paiement
*/
private Date lastPaymentDate;

/**
* La date du prochain paiement
*/
private Date nextPaymentDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.funixproductions.api.payment.paypal.service.subscriptions.services;

import com.funixproductions.api.payment.paypal.client.clients.PaypalPlanClient;
import com.funixproductions.api.payment.paypal.client.dtos.responses.PaypalPlanDTO;
import com.funixproductions.core.crud.dtos.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j(topic = "PaypalPlanService")
public class PaypalPlanService implements PaypalPlanClient {

@Override
public PaypalPlanDTO create(PaypalPlanDTO paypalPlanDTO) {
return null;
}

@Override
public PaypalPlanDTO getPlanById(String id) {
return null;
}

@Override
public PaypalPlanDTO updatePlan(String id, PaypalPlanDTO paypalPlanDTO) {
return null;
}

@Override
public PaypalPlanDTO activatePlan(String id) {
return null;
}

@Override
public PaypalPlanDTO deactivatePlan(String id) {
return null;
}

@Override
public PaypalPlanDTO updatePricePlan(String id, Double newPrice) {
return null;
}

@Override
public PageDTO<PaypalPlanDTO> getAll(String page, String elemsPerPage, String search, String sort) {
return null;
}
}