0

I am trying to redirect to a external link using a rest api , but the desired link is not displayed and i got this the console : enter image description here i'm using angular 4 / spring boot 2 ** when I send the request with postman it return the code html of the link :

enter image description here

my spring code :

@GetMapping("/create")
static public RedirectView createPayment(HttpServletRequest req, HttpServletResponse res)
        throws Exception {

    TransactionRequest request = new TransactionRequest();

    request.setOrderId("1242").setCurrency("MAD").setAmount(1500);
    request.setShippingType(ShippingType.VIRTUAL);
    request.setPaymentMode(PaymentMode.SINGLE);
    request.setPaymentType(PaymentType.CREDIT_CARD); 
    request.setCtrlRedirectURL("http://capmission.ma");
    request.setCustomerIP("105.159.248.185");

    try {
        request.validate();
    } catch (BadRequestException e) {
        throw new Exception("Ooops, an error occurred validating the payment request: " + e.getMessage());
    }
    Connect2payClient c2p = new Connect2payClient("https://paiement.payzone.ma", "104747", "vbK7@pQ3G@W9X2k2");
    TransactionResponse response = null;
    try {
        response = c2p.prepareTransaction(request);
    } catch (Exception e) {
        throw new Exception("Ooops, an error occurred preparing the payment: " + e.getMessage());
    }
    if (response != null && ResultCode.SUCCESS.equals(response.getCode())) {
        response.setCustomerToken(response.getCustomerToken());
        String redirectURL = response.getCustomerRedirectURL();
        System.out.println(redirectURL);
        if (redirectURL != null) {
            return new RedirectView("https://www.google.com");
        }
    } else {
        System.out.println(response.getCode());
    }
    return null;
}

my angular code :

//service : 
    public testPaiementEnLigne2(){
        return 
         this.http.get(this.baseUrl+"payzone/create").map(data=>data.json());
    }

the fonction that do the redirection :

payer2(){
    this.paiementService.testPaiementEnLigne2().subscribe(
      data=>{
        console.log(data);
      },
      err=>{
        console.log(err);
    });
  } 

1 Answer 1

1

You expect JSON but you get HTML:

//service : 
    public testPaiementEnLigne2(){
        return 
         this.http.get(this.baseUrl+"payzone/create").map(data=>data.text());
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.