Vote count:
0
I am trying to integrate Paypal REST service to process payment on my website. I have developers accounts in order to test my servlets and jsp pages. I can get a token, emulate a payment and get approval URL from paypal servers. But when I go to that approval URL and login, an error message shows up that you can see below.
I have no error code or explicit message that helps me fixing this. Do you have any idea about what can cause this behavior?
Thanks for helping.
Here is the servlet I am using:
@WebServlet(name="PaypalPayment", urlPatterns={"/paypal-payment.html"}) public class Paypal_Payment extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
OAuthTokenCredential token;
String accessToken;
APIContext apiContext;
Payment createdPayment;
String paypalValidationURL;
try{
token = new OAuthTokenCredential(Constantes.PAYPAL_CLIENT_ID, Constantes.PAYPAL_CLIENT_SECRET);
accessToken = token.getAccessToken();
//Token récupéré => on crée le context paypal avec tous les objets (ici tout est en dur pour le test, apres on récuperera les données entrée par l'user)
apiContext = new APIContext(accessToken);
//Montant de la transaction
Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setTotal("25");
//Création de la transaction
Transaction transaction = new Transaction();
transaction.setDescription("Creating Payment");
//Passage de l'objet montant à la transaction
transaction.setAmount(amount);
//Liste des transactions
List<Transaction> transactions = new ArrayList<Transaction>();
transactions.add(transaction);
//Création d'un objet Payer avec les infos de l'user
Payer payer = new Payer();
payer.setPaymentMethod("paypal");
//Création de l'objet payment, on lui passe le but du payment (acheter ou vendre), le payer et la liste des transactions
Payment payment = new Payment();
payment.setIntent("sale");
payment.setPayer(payer);
payment.setTransactions(transactions);
//Gestion des urls de retour (en cas d'annulation et de validation
RedirectUrls redirectUrls = new RedirectUrls();
redirectUrls.setCancelUrl("http://localhost:8080/a-vos-cas-JSP/paypal-cancel.html");
redirectUrls.setReturnUrl("http://localhost:8080/a-vos-cas-JSP/paypal-response.html");
//On passe les urls à l'objet payment
payment.setRedirectUrls(redirectUrls);
//On execute le payment
//payment.create(apiContext);
createdPayment = payment.create(apiContext);
System.out.println("TEST : " + createdPayment);
paypalValidationURL = createdPayment.getLinks().get(1).getHref();
System.out.println("URL de validation = " + paypalValidationURL);
response.sendRedirect(response.encodeURL(paypalValidationURL));
//getServletContext().getNamedDispatcher(paypalValidationURL).forward(request, response);
}catch(PayPalRESTException e){
e.printStackTrace();
}
}
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire