2013-11-15 54 views
0

我想问一个简单的查询,我的客户已经购买了PayPal预付款账户,每月额外支付5美元用于支付整合到他们网站的额外服务。PayPal支付Java开发人员

我想问一下使用此帐户可以使用哪些功能?我在谷歌搜索,但没有找到相关信息。

我的客户要求所有的付款应该在我的网站上完成,不要让用户重定向到任何购买的贝宝官方网站。

我该如何使用此帐户执行此操作,我可以使用哪些功能以及服务或API?

+0

'我的客户要求所有的付款都应该在我的网站上完成,不要让用户重定向到任何购买的贝宝官方网站。' 你不能。你可以做的最好的是提供paypal与你的网站设计无缝集成。但是无论你做什么,你都必须将你的客户重定向到paypal--这是一个安全限制。否则,第三方可以获得客户的PayPal名称和密码。 – bezmax

+0

感谢您的重播,还有另一项名为PayFlow和PayFlow Pro的服务,这是很好用的。 –

+0

如果您的客户要支付他的PayPal账户,他将被重定向到PayPal。有关如何使用payflow pro可以做什么的信息,请参阅以下信息:https://www.paypal.com/cgi-bin/webscr?cmd=xpt/Marketing/demo/wppro/WPProDemo6-outside(本页特别说明客户将被重定向到PayPal)。 PayFlow和PayFlow Pro AFAIK之间的区别在于,它是一种简单的重定向到PayPal,另一种支持使用您的设计和使用贝宝作为无缝信用卡网关(根本没有重定向)。 – bezmax

回答

1

这是您的问题的解决方案。只需遵循以下几点。

  1. 创建一个maven web应用程序。
  2. 包括以下依赖

     <dependency> 
          groupId>com.paypal.sdk</groupId> 
            <artifactId>adaptivepaymentssdk</artifactId> 
            <version>2.5.106</version> 
          </dependency> 
    

3.Here是包含的付款电子邮件到电子邮件的代码的类。

public class PaymentTest { 
    public static boolean fundtransferFromClientAcount() { 

     PayRequest req = new PayRequest(); 
     RequestEnvelope requestEnvelope = new RequestEnvelope(); 
     requestEnvelope.setErrorLanguage("en_US"); 
     req.setRequestEnvelope(requestEnvelope); 
     List<Receiver> receiver = new ArrayList<Receiver>(); 
     Receiver rec = new Receiver(); 
     /** (Required) Amount to be paid to the receiver */ 
     rec.setAmount(10.00); 
     /**Reciever and Sender should be register on paypal with same emailid.*/ 
     rec.setEmail("Reciever Email Id"); 
     receiver.add(rec); 
     ReceiverList receiverlst = new ReceiverList(receiver); 
     req.setReceiverList(receiverlst); 
     req.setSenderEmail("Sender Email"); 
     req.setActionType("PAY"); 
     req.setCancelUrl("Cancel Url"); 
     req.setCurrencyCode("USD"); 
     /** Here we need to give success url */ 
     req.setReturnUrl("return or success url"); 
     Map<String, String> configurationMap =Configuration.getAcctAndConfig(); 
     // Creating service wrapper object to make an API call by loading 
     // configuration map. 
     AdaptivePaymentsService service = new AdaptivePaymentsService(
       configurationMap); 
     try { 
      PayResponse resp = service.pay(req); 
      if (resp != null) { 
       if (resp.getResponseEnvelope().getAck().toString() 
         .equalsIgnoreCase("SUCCESS")) { 
        Map<Object, Object> map = new LinkedHashMap<Object, Object>(); 
        map.put("Ack", resp.getResponseEnvelope().getAck()); 

        /** 
        * Correlation identifier. It is a 13-character, 
        * alphanumeric string (for example, db87c705a910e) that is 
        * used only by PayPal Merchant Technical Support. Note: You 
        * must log and store this data for every response you 
        * receive. PayPal Technical Support uses the information to 
        * assist with reported issues. 
        */ 
        map.put("CorrelationID", resp.getResponseEnvelope() 
          .getCorrelationId()); 

        /** 
        * Date on which the response was sent, for example: 
        * 2012-04-02T22:33:35.774-07:00 Note: You must log and 
        * store this data for every response you receive. PayPal 
        * Technical Support uses the information to assist with 
        * reported issues. 
        */ 
        map.put("TimeStamp", resp.getResponseEnvelope() 
          .getTimestamp()); 

        /** 
        * The pay key, which is a token you use in other Adaptive 
        * Payment APIs (such as the Refund Method) to identify this 
        * payment. The pay key is valid for 3 hours; the payment 
        * must be approved while the pay key is valid. 
        */ 
        map.put("PayKey", resp.getPayKey()); 

        /** 
        * The status of the payment. Possible values are: CREATED – 
        * The payment request was received; funds will be 
        * transferred once the payment is approved COMPLETED – The 
        * payment was successful INCOMPLETE – Some transfers 
        * succeeded and some failed for a parallel payment or, for 
        * a delayed chained payment, secondary receivers have not 
        * been paid ERROR – The payment failed and all attempted 
        * transfers failed or all completed transfers were 
        * successfully reversed REVERSALERROR – One or more 
        * transfers failed when attempting to reverse a payment 
        * PROCESSING – The payment is in progress PENDING – The 
        * payment is awaiting processing 
        */ 
        map.put("Payment Execution Status", 
          resp.getPaymentExecStatus()); 
        if (resp.getDefaultFundingPlan() != null) { 
         /** Default funding plan. */ 
         map.put("Default Funding Plan", resp 
           .getDefaultFundingPlan().getFundingPlanId()); 
        } 
        // Skipping for Implicit Payments 
        if (!resp.getPaymentExecStatus().equalsIgnoreCase(
          "Completed")) { 
         map.put("Redirect URL", 
           "<a href=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=" 
             + resp.getPayKey() 
             + ">https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=" 
             + resp.getPayKey() + "</a>"); 
        } 


        for (Entry<Object, Object> entry : map.entrySet()) { 
         System.out.println("Key : " + entry.getKey() 
           + " Value : " + entry.getValue()); 
        } 
        return true; 
       } else { 
        return false; 
       } 
      } 

     } catch (Exception e) { 
      e.printStackTrace(); 
      return false; 
     } 

     return true; 
    } 

    public static void main(String[] args) { 

     fundtransferFromClientAcount(); 
    } 

} 

4.Configuration文件

/** 
* For a full list of configuration parameters refer in wiki page(https://github.com/paypal/sdk-core-java/wiki/SDK-Configuration-Parameters). 
*/ 
public class Configuration { 

     // Creates a configuration map containing credentials and other required configuration parameters. 
     public static final Map<String,String> getAcctAndConfig(){ 
       Map<String,String> configMap = new HashMap<String,String>(); 
       configMap.putAll(getConfig()); 

       // Account Credential 
       configMap.put("acct1.UserName", "sandbox account username"); 
       configMap.put("acct1.Password", "sandbox account password"); 
       configMap.put("acct1.Signature", "sandbox account signature"); 
       configMap.put("acct1.AppId", "sandbox account generated AppId"); 

       // Sample Certificate credential 
       // configMap.put("acct2.UserName", "certuser_biz_api1.paypal.com"); 
       // configMap.put("acct2.Password", "D6JNKKULHN3G5B8A"); 
       // configMap.put("acct2.CertKey", "password"); 
       // configMap.put("acct2.CertPath", "resource/sdk-cert.p12"); 
       // configMap.put("acct2.AppId", "APP-80W284485P519543T"); 

       // Sandbox Email Address 
       configMap.put("sandbox.EmailAddress", "email address for sandbox"); 

       return configMap; 
     } 

     public static final Map<String,String> getConfig(){ 
       Map<String,String> configMap = new HashMap<String,String>(); 

       // Endpoints are varied depending on whether sandbox OR live is chosen for mode 
       configMap.put("mode", "sandbox"); 

       // These values are defaulted in SDK. If you want to override default values, uncomment it and add your value. 
       // configMap.put("http.ConnectionTimeOut", "5000"); 
       // configMap.put("http.Retry", "2"); 
       // configMap.put("http.ReadTimeOut", "30000"); 
       // configMap.put("http.MaxConnection", "100"); 
       return configMap; 
     } 
} 

5.Just获得所有所需的参数,它会正常工作。