All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lsn.spring.bluemedia.payment.domain.BlueMediaGatewayController Maven / Gradle / Ivy

The newest version!
package io.lsn.spring.bluemedia.payment.domain;

import io.lsn.spring.bluemedia.payment.domain.entity.configuration.ServiceConfiguration;
import io.lsn.spring.utilities.configuration.condition.ConditionalOnConfiguration;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@ConditionalOnConfiguration(name = "io.lsn.spring.bluemedia.payment", type = ConditionalOnConfiguration.Type.ENDPOINT)
@RestController
@RequestMapping("/api/bmgateway")
public class BlueMediaGatewayController {

    private static final Logger logger = Logger.getLogger(BlueMediaGatewayController.class);

    private BlueMediaGatewayService service;

    @Autowired
    public BlueMediaGatewayController(BlueMediaGatewayService service) {
        this.service = service;
    }

    /**
     * ITN confirmation endpoint
     *
     * @param transactions list of transactions
     */
    @RequestMapping(value = "/itn", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @SuppressWarnings("squid:S00112")
    public ResponseEntity itnRequest(String transactions) {
        String response = service.processItn(transactions);
        return new ResponseEntity<>(response, response != null ? HttpStatus.OK : HttpStatus.BAD_REQUEST);
    }


    @RequestMapping(value = "/confirmation", method = RequestMethod.GET)
    @SuppressWarnings({"squid:S00117", "squid:S00112"})
    public ResponseEntity transactionAuthConfirmation(
            @RequestParam(value = "ServiceID") String serviceId,
            @RequestParam(value = "OrderID") String orderId,
            @RequestParam(value = "Hash") String hash) {
        ServiceConfiguration configuration = service.getConfigurationByServiceId(serviceId);
        Boolean equals = service.verifyPaymentReturn(serviceId, orderId, hash, configuration);
        return new ResponseEntity(null, equals ? HttpStatus.OK : HttpStatus.I_AM_A_TEAPOT);
    }


    /**
     * Health check endpoint for blue media gateway
     */
    @RequestMapping(value = "/itn", method = RequestMethod.GET)
    public ResponseEntity healthCheck() {
        return new ResponseEntity(null, HttpStatus.OK);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy