java中测试帐户中的Paypal付款失败

发布于 2024-11-18 00:46:48 字数 2869 浏览 4 评论 0原文

我正在尝试在 Paypal DoDirectPayment 方法中开发应用程序,正在创建测试沙箱帐户,并使用以下代码和我自己的 API 凭据,但我得到确认失败...

如果有人知道如何解决此问题,请分享给我。

谢谢提前。

public class DoDirectPayment 
{
private NVPCallerServices caller = null;

public String DoDirectPaymentCode(String paymentAction,String amount,String cardType,
                            String acct,String expdate,String cvv2, String firstName,
                            String lastName, String street, String city, String state, 
                            String zip, String countryCode)
{
    NVPEncoder encoder = new NVPEncoder();
    NVPDecoder decoder = new NVPDecoder();

    try
    {

        caller = new NVPCallerServices();
    APIProfile profile = ProfileFactory.createSignatureAPIProfile();
        /*
         WARNING: Do not embed plaintext credentials in your application code.
         Doing so is insecure and against best practices.
         Your API credentials must be handled securely. Please consider
         encrypting them for use in any production environment, and ensure
         that only authorized individuals may view or modify them.
         */
    // Set up your API credentials, PayPal end point, API operation and version.
        profile.setAPIUsername("sdk-three_api1.sdk.com");
        profile.setAPIPassword("QFZCWN5HZM8VBG7Q");
        profile.setSignature("AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ");
        profile.setEnvironment("sandbox");
        profile.setSubject("");
        caller.setAPIProfile(profile);

        encoder.add("VERSION", "51.0");
        encoder.add("METHOD","DoDirectPayment");

    // Add request-specific fields to the request string.
        encoder.add("PAYMENTACTION",paymentAction);
        encoder.add("AMT",amount);
        encoder.add("CREDITCARDTYPE",cardType);     
        encoder.add("ACCT",acct);                       
        encoder.add("EXPDATE",expdate);
        encoder.add("CVV2",cvv2);
        encoder.add("FIRSTNAME",firstName);
        encoder.add("LASTNAME",lastName);                                       
        encoder.add("STREET",street);
        encoder.add("CITY",city);   
        encoder.add("STATE",state);         
        encoder.add("ZIP",zip); 
        encoder.add("COUNTRYCODE",countryCode);

    // Execute the API operation and obtain the response.
        String NVPRequest = encoder.encode();
        String NVPResponse =(String) caller.call(NVPRequest);
        decoder.decode(NVPResponse);

    } catch(Exception ex)
    {
        ex.printStackTrace();
    }
    return decoder.get("ACK");
}

public static void main(String[] args) {

    DoDirectPayment obj=new DoDirectPayment();
    System.out.println(obj.DoDirectPaymentCode("Authorization ", "1", "Visa", "1234123412341234", "122012", "123", "testname", "testname", "chennai", "chennai", "TX", "77570", "US"));

}

} 

I am trying to develop application in Paypal DoDirectPayment method am creating testing sandbox account and use the following code with my own API credentials but i get acknowledgement is failure ...

If any one know how to rid out this issue share to me.,

Thanks in advance.

public class DoDirectPayment 
{
private NVPCallerServices caller = null;

public String DoDirectPaymentCode(String paymentAction,String amount,String cardType,
                            String acct,String expdate,String cvv2, String firstName,
                            String lastName, String street, String city, String state, 
                            String zip, String countryCode)
{
    NVPEncoder encoder = new NVPEncoder();
    NVPDecoder decoder = new NVPDecoder();

    try
    {

        caller = new NVPCallerServices();
    APIProfile profile = ProfileFactory.createSignatureAPIProfile();
        /*
         WARNING: Do not embed plaintext credentials in your application code.
         Doing so is insecure and against best practices.
         Your API credentials must be handled securely. Please consider
         encrypting them for use in any production environment, and ensure
         that only authorized individuals may view or modify them.
         */
    // Set up your API credentials, PayPal end point, API operation and version.
        profile.setAPIUsername("sdk-three_api1.sdk.com");
        profile.setAPIPassword("QFZCWN5HZM8VBG7Q");
        profile.setSignature("AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ");
        profile.setEnvironment("sandbox");
        profile.setSubject("");
        caller.setAPIProfile(profile);

        encoder.add("VERSION", "51.0");
        encoder.add("METHOD","DoDirectPayment");

    // Add request-specific fields to the request string.
        encoder.add("PAYMENTACTION",paymentAction);
        encoder.add("AMT",amount);
        encoder.add("CREDITCARDTYPE",cardType);     
        encoder.add("ACCT",acct);                       
        encoder.add("EXPDATE",expdate);
        encoder.add("CVV2",cvv2);
        encoder.add("FIRSTNAME",firstName);
        encoder.add("LASTNAME",lastName);                                       
        encoder.add("STREET",street);
        encoder.add("CITY",city);   
        encoder.add("STATE",state);         
        encoder.add("ZIP",zip); 
        encoder.add("COUNTRYCODE",countryCode);

    // Execute the API operation and obtain the response.
        String NVPRequest = encoder.encode();
        String NVPResponse =(String) caller.call(NVPRequest);
        decoder.decode(NVPResponse);

    } catch(Exception ex)
    {
        ex.printStackTrace();
    }
    return decoder.get("ACK");
}

public static void main(String[] args) {

    DoDirectPayment obj=new DoDirectPayment();
    System.out.println(obj.DoDirectPaymentCode("Authorization ", "1", "Visa", "1234123412341234", "122012", "123", "testname", "testname", "chennai", "chennai", "TX", "77570", "US"));

}

} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2024-11-25 00:46:48

PAYMENTACTION 参数中有拼写错误:
“授权”应替换为“授权”(只需删除末尾多余的空格)

You have a typo in the PAYMENTACTION parameter:
"Authorization " should be replaced with "Authorization" (just remove redundant space at the end)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文