2017-05-26 19 views
6

私の現在のJava/Springプロジェクトでは、PayPalとの統合段階にあります。 hereの指示に従って、支払い処理を処理するJavaクラスを設定した後、私は自分のアプリケーションを実行し、paypalで注文をチェックアウトしようとします。PayPal SDKが支払い確認ページからプロフィールページに移動

私はPayPalのログインページに正しくリダイレ​​クトされ、ログイン後、この支払いレビューページにしています:

enter image description here

が、その後、私は代わりに支払いを完了するの、「続行」をクリックした後、プロフィールページにリダイレクトされています。ここで

enter image description here

私のコードです:

Paypal prop = this.paypalDao.get(); 
String clientId = prop.getClientID(); 
String clientSecret = prop.getClientSecret(); 
APIContext apiContext = new APIContext(clientId, clientSecret, "sandbox"); 

if(payerId != null) { 
    if(guid != null) { 
    Payment payment = new Payment(); 
    payment.setId(map.get(guid)); 

    PaymentExecution paymentExecution = new PaymentExecution(); 
    paymentExecution.setPayerId(payerId); 
    payment.execute(apiContext, paymentExecution); 

    String url = request.getContextPath(); 
    return url+"/orders"; 
    } 
} else { 
    List<Produto> lista_de_produtos = this.getListaDeProdutos(clienteId); 

    Double total = 0.0; 
    for(Produto produto : lista_de_produtos) 
    total = total + produto.getPreco(); 
    DecimalFormat df = new DecimalFormat("0.00"); 
    String svalue = df.format(total).replace(',', '.'); 

    Details details = new Details(); 
    details.setSubtotal(svalue); 

    Amount amount = new Amount(); 
    amount.setCurrency("BRL"); 
    amount.setTotal(svalue); 
    amount.setDetails(details); 

    Transaction transaction = new Transaction(); 
    transaction.setAmount(amount); 
    transaction.setDescription(lista_de_produtos.toString()); 

    List<Transaction> transactions = new ArrayList<Transaction>(); 
    transactions.add(transaction); 

    Payer payer = new Payer(); 
    payer.setPaymentMethod("paypal"); 

    Payment payment = new Payment(); 
    payment.setIntent("sale"); 
    payment.setPayer(payer); 
    payment.setTransactions(transactions); 

    RedirectUrls redirectUrls = new RedirectUrls(); 
    guid = UUID.randomUUID().toString(); 
    String url = request.getContextPath(); 
    redirectUrls.setCancelUrl(url+"/cart"); 
    redirectUrls.setReturnUrl(url+"/paypal/checkout/"+clientId+"/?guid=" + guid); 
    payment.setRedirectUrls(redirectUrls); 

    Payment createdPayment = payment.create(apiContext); 
    Iterator<Links> links = createdPayment.getLinks().iterator(); 
    while (links.hasNext()) { 
    Links link = links.next(); 
    if (link.getRel().equalsIgnoreCase("approval_url")) { 
     map.put("redirectURL", link.getHref()); 
     redirectURL = link.getHref(); 
    } 
    } 
    map.put(guid, createdPayment.getId()); 
    payment.setId(map.get(guid)); 
} 

return redirectURL; 

誰かが私がここで何をしないのです、教えてもらえますか?

+1

少なくとも電話、電子メールIDなどのような個人的な詳細を隠します。 –

+0

request.getContextPath()とは何ですか?これが相対URL(ドメイン名なし)の場合、PayPalはどこに顧客を送り返すかを知らない。 –

答えて

2

は、この値を印刷してみてください:

System.out.println(url+"/paypal/checkout/"+clientId+"/?guid=" + guid); 

結果はhttps://www.yoursite.com/paypal/checkout/<number>/?guid=<number>あるべきか、そこに直接でしょうページ(バイトを節約するためにhttps://を残して、サーバーの構成に応じて大丈夫かもしれません)。あなたは試してみてください

追加試験:あなたのサイトにキャンセル

  1. してみてください。
  2. paypalのサイトで支払いをキャンセルしてみてください。

Iffは動作しますが、2番目のものは動作しません。そうすれば、paypalは適切にリダイレクトされません。つまり、正しい文字列を指定していない可能性があります。 @Emileによるコメントも参照してください。

+0

'' https:// 'を除いてバイトを保存する...... [間違ったサイト?](https://codegolf.stackexchange.com/)LOL:P – HyperNeutrino

+0

@HyperNeutrino支払い処理システムによっては、 URLの長さは、公式の標準よりも許容されます。例えば。銀行は従来のバックエンドで固定文字列を使用するため、代わりに255文字を使用します。保存された8バイトは、ときどき役立つことがあります。私はpaypalのためにそれを見上げなかったので、それは不必要かもしれません。 – aphid

関連する問題