Skip to content

Commit

Permalink
[Payment] Embedded Payment-Paypal project into Payment project like a…
Browse files Browse the repository at this point in the history
… dependency #1003
  • Loading branch information
khanhtranduy committed Oct 29, 2024
1 parent 907d016 commit 6872f4b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.instancio.Select.field;

import java.util.UUID;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Import(IntegrationTestConfiguration.class)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class PaymentProviderControllerIT extends AbstractControllerIT {

private static final String PAYMENT_PROVIDERS_URL = "v1/storefront/payment-providers";
private static final String ADDITIONAL_SETTINGS_URL_TEMPLATE = "v1/payment-providers/{id}/additional-settings";

@Autowired
PaymentProviderRepository paymentProviderRepository;
Expand Down Expand Up @@ -57,30 +53,4 @@ void test_getPaymentProviders_shouldReturnPaymentProviders() {
.body(".", hasSize(1))
.log().ifValidationFails();
}

@Test
void test_getAdditionalSettings_shouldReturnAdditionalSettings() {
RestAssured.given(getRequestSpecification())
.auth().oauth2(getAccessToken("admin", "admin"))
.pathParam("id", paymentProvider.getId())
.when()
.get(ADDITIONAL_SETTINGS_URL_TEMPLATE)
.then()
.statusCode(HttpStatus.OK.value())
.body(equalTo(paymentProvider.getAdditionalSettings()))
.log().ifValidationFails();
}

@Test
void test_getAdditionalSettings_shouldReturn404_whenInvalidId() {
String invalidId = UUID.randomUUID().toString();

RestAssured.given(getRequestSpecification())
.pathParam("id", invalidId)
.when()
.get(ADDITIONAL_SETTINGS_URL_TEMPLATE)
.then()
.statusCode(HttpStatus.NOT_FOUND.value())
.log().ifValidationFails();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/storefront/**").permitAll()
.requestMatchers("/backoffice/**").hasRole("ADMIN")
.requestMatchers("/payment-providers/**").permitAll()
.requestMatchers("/capture-payment").permitAll()
.requestMatchers("/actuator/**").permitAll()
.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public class PaymentController {

private final PaymentService paymentService;

@PostMapping(value = "/storefront/payments/init")
@PostMapping(value = "/init")
public InitPaymentResponse initPayment(@Valid @RequestBody InitPaymentRequest initPaymentRequest) {
return paymentService.initPayment(initPaymentRequest);
}

@PostMapping(value = "/storefront/payments/capture")
@PostMapping(value = "/capture")
public CapturePaymentResponse capturePayment(@Valid @RequestBody CapturePaymentRequest capturePaymentRequest) {
return paymentService.capturePayment(capturePaymentRequest);
}

@GetMapping(value = "/storefront/payments/cancel")
@GetMapping(value = "/cancel")
public ResponseEntity<String> cancelPayment() {
return ResponseEntity.ok("Payment cancelled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ public ResponseEntity<List<PaymentProviderVm>> getPaymentProviders() {
return ResponseEntity.ok(paymentProviderService.getEnabledPaymentProviders());
}

@GetMapping("/payment-providers/{id}/additional-settings")
public ResponseEntity<String> getAdditionalSettings(@PathVariable("id") String id) {
return ResponseEntity.ok(paymentProviderService
.getAdditionalSettingsByPaymentProviderId(id));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { CapturePaymentRequest } from '@/modules/paymentPaypal/models/CapturePay
import { CapturePaymentPaypalResponse } from '@/modules/paymentPaypal/models/CapturePaymentPaypalResponse';
import apiClientService from '@/common/services/ApiClientService';

const baseUrl = '/api/payment/storefront';
const baseUrl = '/api/payment';

export async function initPaymentPaypal(
paymentPaypalRequest: InitPaymentPaypalRequest
): Promise<InitPaymentPaypalResponse> {
const res = await apiClientService.post(`${baseUrl}/payments/init`, JSON.stringify(paymentPaypalRequest));
const res = await apiClientService.post(`${baseUrl}/init`, JSON.stringify(paymentPaypalRequest));
if (res.ok) {
return res.json();
}
throw new Error(res.statusText);
}

export async function capturePaymentPaypal(capturePaymentRequest: CapturePaymentRequest): Promise<CapturePaymentPaypalResponse> {
const res = await apiClientService.post(`${baseUrl}/payments/capture`, JSON.stringify(capturePaymentRequest));
const res = await apiClientService.post(`${baseUrl}/capture`, JSON.stringify(capturePaymentRequest));
if (res.ok) {
return res.json();
}
Expand Down

0 comments on commit 6872f4b

Please sign in to comment.