paypalpaypal-sandboxpaypal-adaptive-paymentsnvp

Invalid transaction ID in Docapture method paypal api


I'm doing a DoCapture and using the transaction id of a DoDirectPayment. But every time when I capture the payment it shows 'Invalid transaction id'. This happens when I try to capture a peyment from direct credit card payment, and also this credit card payment is through DoDirectPayment method. But if do expressCheckout by going to my PayPal account and complete my transaction, this also gives me transaction id. If I capture the payment using this transaction id, payment process completes successfully ! I don't know what is going on ! Please anyone help me to get out of the problem! I'm using PayPal API Version 59.0 My sample code

                Session["stage"] = ASPDotNetSamples.Constants.ENVIRONMENT; //SandBox Environment
                //here my api credentials
                SetProfile.SessionProfile = SetProfile.CreateAPIProfile(ASPDotNetSamples.Constants.API_USERNAME,
                    ASPDotNetSamples.Constants.API_PASSWORD, ASPDotNetSamples.Constants.API_SIGNATURE, "", "",
                    ASPDotNetSamples.Constants.ENVIRONMENT);


                //NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
                //NVPCodec encoder = new NVPCodec();
                com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
                NVPCodec encoder = new NVPCodec();

                encoder["METHOD"] = "DoCapture";
                encoder["TRXTYPE"] = "D";
                encoder["AUTHORIZATIONID"] = authorization_id.; //the authrization id i got from the dodirectpayment
                encoder["COMPLETETYPE"] = CompleteCodeType; //completecodetype is completed
                double dAmount = Convert.ToDouble(actualAmount);
                encoder["AMT"] = String.Format("{0:0.00}", dAmount);                       

                string pStrrequestforNvp = encoder.Encode();
                string pStresponsenvp = caller.Call(pStrrequestforNvp);

                NVPCodec decoder = new NVPCodec();
                decoder.Decode(pStresponsenvp);
                string parentTransactionID = decoder["PARENTTRANSACTIONID"];
                string strAck = decoder["ACK"];

                if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning"))
                {
                    string pStrResQue = "AUTHORIZATIONID=" + decoder["AUTHORIZATIONID"] + "&" +
                        //"PAYMENTSTATUS=" + decoder["PAYMENTSTATUS"] + "&" +
                                        "PAYMENTSTATUS=" + CompleteCodeType + "&" +
                                        "AMT=" + decoder["AMT"] + "&" +
                                        "TRANSACTIONID=" + decoder["TRANSACTIONID"];                        
                       // if  Payment is done successfully

                }
                else
                {
                     // if Payment is pending

                    string pStrError = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                                       "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                                       "Desc2=" + decoder["L_LONGMESSAGE0"];                        
                    Response.Redirect("APIError.aspx?" + pStrError);
                }

Thanks in advance!


Solution

  • See DoCapture Documentation here

    See DoDirectPayment Documentation here