从Paypal电子邮件获取Paypal付款人ID

时间:2019-06-18 07:30:34

标签: java paypal

因此,我想在玩家自动给我付款后将付款发送给我的玩家。但是我根本不知道他们的付款人ID。我已经尝试了数十种方法,但仍然无法正常工作!

我尝试使用他们的电子邮件,商家,我的付款人ID(ik)等仍然无效。

    public Authorization getPaypalConfirmation(String email, double price, String description) {
         if (!this.enabled) {
             return null;
         }
        /*
         * Flow would look like this: 
         * 1. Create Payer object and set PaymentMethod 
         * 2. Set RedirectUrls and set cancelURL and returnURL 
         * 3. Set Details and Add PaymentDetails
         * 4. Set Amount
         * 5. Set Transaction
         * 6. Add Payment Details and set Intent to "authorize"
         * 7. Create APIContext by passing the clientID, secret and mode
         * 8. Create Payment object and get paymentID
         * 9. Set payerID to PaymentExecution object
         * 10. Execute Payment and get Authorization
         * 
         */

        Payer crunchifyPayer = new Payer();
        crunchifyPayer.setPaymentMethod("paypal");
        // Redirect URLs
        RedirectUrls crunchifyRedirectUrls = new RedirectUrls();
        crunchifyRedirectUrls.setCancelUrl(this.getCancelurl());
        crunchifyRedirectUrls.setReturnUrl(this.getReturnurl());

        // Set Payment Details Object
        Details crunchifyDetails = new Details();
        crunchifyDetails.setSubtotal(price + "");

        // Set Payment amount
        Amount crunchifyAmount = new Amount();
        crunchifyAmount.setCurrency(this.getCurrency());
        crunchifyAmount.setTotal(price + "");
        crunchifyAmount.setDetails(crunchifyDetails);

        // Set Transaction information
        Transaction crunchifyTransaction = new Transaction();
        crunchifyTransaction.setAmount(crunchifyAmount);
        crunchifyTransaction.setDescription(description);
        List<Transaction> crunchifyTransactions = new ArrayList<Transaction>();
        crunchifyTransactions.add(crunchifyTransaction);

        // Add Payment details
        Payment crunchifyPayment = new Payment();

        // Set Payment intent to authorize
        crunchifyPayment.setIntent("authorize");
        crunchifyPayment.setPayer(crunchifyPayer);
        crunchifyPayment.setTransactions(crunchifyTransactions);
        crunchifyPayment.setRedirectUrls(crunchifyRedirectUrls);

        // Pass the client, secret and mode. The easiest, and most widely used option.
        APIContext crunchifyapiContext = new APIContext(this.clientid, this.getClientsecret(), "sandbox");
        try {

            Payment myPayment = crunchifyPayment.create(crunchifyapiContext);

            System.out.println("createdPayment Obejct Details ==> " + myPayment.toString());

            // Identifier of the payment resource created 
            crunchifyPayment.setId(myPayment.getId());          
            PaymentExecution crunchifyPaymentExecution = new PaymentExecution();
            // Set your PayerID. The ID of the Payer, passed in the `return_url` by PayPal.
            crunchifyPaymentExecution.setPayerId(email);

            // This call will fail as the user has to access Payment on UI. Programmatically
            // there is no way you can get Payer's consent.
            Payment createdAuthPayment = crunchifyPayment.execute(crunchifyapiContext, crunchifyPaymentExecution);
            // Transactional details including the amount and item details.
            Authorization crunchifyAuthorization = createdAuthPayment.getTransactions().get(0).getRelatedResources().get(0).getAuthorization(); 
            return crunchifyAuthorization;
        } catch (PayPalRESTException e) {

            // The "standard" error output stream. This stream is already open and ready to
            // accept output data.
            System.err.println(e.getDetails());
        }
        return null;
    }
18.06 02:38:39 [Server] ERROR [com.paypal.base.HttpConnection] Response code: 400Error response: {"name":"PAYMENT_NOT_APPROVED_FOR_EXECUTION","message":"Payer has not approved payment","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"dec8cb3e6fae5"}
18.06 02:38:39 [Server] WARN name: PAYMENT_NOT_APPROVED_FOR_EXECUTIONmessage: Payer has not approved paymentdetails: 

显示错误,表明付款人未获批准。我敢肯定我会错过他们的付款人ID。

0 个答案:

没有答案