public PayPalTrasactions DoTransaction(string billingAgreementID, string orderDescription, string itemName, double itemAmount, string serviceDescription, out string PaypalResponse)
        {
            string response = string.Empty;

            // Create request object
            DoReferenceTransactionRequestType request = new DoReferenceTransactionRequestType();

            populateRequestObject(request, billingAgreementID, orderDescription, itemName, itemAmount, serviceDescription);
            // Invoke the API
            DoReferenceTransactionReq wrapper = new DoReferenceTransactionReq();

            wrapper.DoReferenceTransactionRequest = request;
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            string requestString = "  Paypal DoTransaction Request billingAgreementID: " + billingAgreementID + ":  ";

            requestString = requestString + JsonConvert.SerializeObject(wrapper);

            // # API call
            // Invoke the DoReferenceTransaction method in service wrapper object
            DoReferenceTransactionResponseType doReferenceTxnResponse = service.DoReferenceTransaction(wrapper);
            PayPalTrasactions responsePaypal = new PayPalTrasactions();

            responsePaypal = ProcessTrasactionResponse(doReferenceTxnResponse);
            response       = JsonConvert.SerializeObject(doReferenceTxnResponse);
            PaypalResponse = requestString + "  Paypal DoTransaction Response billingAgreementID: " + billingAgreementID + " : " + response;
            return(responsePaypal);
        }
        private void setKeyResponseObjects(PayPalAPIInterfaceServiceService service, DoReferenceTransactionResponseType response)
        {
            HttpContext CurrContext = HttpContext.Current;

            CurrContext.Items.Add("Response_apiName", "DoReferenceTransaction");
            CurrContext.Items.Add("Response_redirectURL", null);
            CurrContext.Items.Add("Response_requestPayload", service.getLastRequest());
            CurrContext.Items.Add("Response_responsePayload", service.getLastResponse());

            Dictionary <string, string> responseParams = new Dictionary <string, string>();

            responseParams.Add("Correlation Id", response.CorrelationID);
            responseParams.Add("API Result", response.Ack.ToString());

            if (response.Ack.Equals(AckCodeType.FAILURE) ||
                (response.Errors != null && response.Errors.Count > 0))
            {
                CurrContext.Items.Add("Response_error", response.Errors);
            }
            else
            {
                CurrContext.Items.Add("Response_error", null);
                DoReferenceTransactionResponseDetailsType transactionDetails = response.DoReferenceTransactionResponseDetails;
                responseParams.Add("Transaction ID", transactionDetails.TransactionID);
                responseParams.Add("Payment status", transactionDetails.PaymentInfo.PaymentStatus.ToString());
                if (transactionDetails.PaymentInfo.PendingReason != null)
                {
                    responseParams.Add("Pending reason", transactionDetails.PaymentInfo.PendingReason.ToString());
                }
            }
            CurrContext.Items.Add("Response_keyResponseObject", responseParams);
            Server.Transfer("../APIResponse.aspx");
        }
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            DoReferenceTransactionRequestType request = new DoReferenceTransactionRequestType();

            populateRequestObject(request);

            // Invoke the API
            DoReferenceTransactionReq wrapper = new DoReferenceTransactionReq();

            wrapper.DoReferenceTransactionRequest = request;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            // # API call
            // Invoke the DoReferenceTransaction method in service wrapper object
            DoReferenceTransactionResponseType doReferenceTxnResponse = service.DoReferenceTransaction(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doReferenceTxnResponse);
        }
Exemple #4
0
    public void DoReferenceTransaction()
    {
        DoReferenceTransactionSample       sample = new DoReferenceTransactionSample();
        DoReferenceTransactionResponseType responseDoReferenceTransactionResponseType = sample.DoReferenceTransactionAPIOperation();

        Assert.IsNotNull(responseDoReferenceTransactionResponseType);
        Assert.AreEqual(responseDoReferenceTransactionResponseType.Ack.ToString().ToUpper(), "SUCCESS");
    }
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            DoReferenceTransactionRequestType request = new DoReferenceTransactionRequestType();

            populateRequestObject(request);

            // Invoke the API
            DoReferenceTransactionReq wrapper = new DoReferenceTransactionReq();

            wrapper.DoReferenceTransactionRequest = request;
            PayPalAPIInterfaceServiceService   service = new PayPalAPIInterfaceServiceService();
            DoReferenceTransactionResponseType doReferenceTxnResponse = service.DoReferenceTransaction(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doReferenceTxnResponse);
        }
        private PayPalTrasactions ProcessTrasactionResponse(DoReferenceTransactionResponseType setECResponse)
        {
            PayPalTrasactions responseObject = new PayPalTrasactions();

            responseObject.ApiStatus = setECResponse.Ack.ToString();
            if (setECResponse.Ack.Equals(AckCodeType.FAILURE) ||
                (setECResponse.Errors != null && setECResponse.Errors.Count > 0))
            {
                responseObject.ResponseError = setECResponse.Errors;
            }
            else
            {
                responseObject.ResponseError = null;
                DoReferenceTransactionResponseDetailsType transactionDetails = setECResponse.DoReferenceTransactionResponseDetails;
                responseObject.TransactionID      = transactionDetails.TransactionID;
                responseObject.BillingAgreementID = transactionDetails.BillingAgreementID;

                if (transactionDetails.PaymentInfo != null)
                {
                    if (transactionDetails.PaymentInfo.PaymentStatus != null)
                    {
                        responseObject.PaymentStatus = transactionDetails.PaymentInfo.PaymentStatus.Value.ToString();
                    }
                    if (transactionDetails.PaymentInfo.PendingReason != null)
                    {
                        responseObject.PendingReason = transactionDetails.PaymentInfo.PendingReason.Value.ToString();
                    }
                    responseObject.PaymentDate   = transactionDetails.PaymentInfo.PaymentDate.ToString();
                    responseObject.GrossAmount   = transactionDetails.PaymentInfo.GrossAmount.value;
                    responseObject.TransactionID = transactionDetails.PaymentInfo.TransactionID;


                    responseObject.ItemTotal = transactionDetails.PaymentInfo.GrossAmount.value;

                    //responseObject.ResponseError = transactionDetails.PaymentInfo.PaymentError;

                    // comment by nitendra 16 March 2016
                    //responseObject.OrderTotal = transactionDetails.Amount.value;

                    responseObject.OrderTotal = transactionDetails.PaymentInfo.GrossAmount.value;
                }
            }
            return(responseObject);
        }
Exemple #7
0
        public void DoReferenceTranscations()
        {
            DoReferenceTransactionRequestType request = new DoReferenceTransactionRequestType();

            populateRequestObject(request);

            // Invoke the API
            DoReferenceTransactionReq wrapper = new DoReferenceTransactionReq();

            wrapper.DoReferenceTransactionRequest = request;


            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            DoReferenceTransactionResponseType doReferenceTxnResponse = service.DoReferenceTransaction(wrapper);


            //setKeyResponseObjects(service, doReferenceTxnResponse);
        }
Exemple #8
0
    //#DoReferenceTransaction API Operation
    //The DoReferenceTransaction API operation processes a payment from a buyer’s account, which is identified by a previous transaction.
    public DoReferenceTransactionResponseType DoReferenceTransactionAPIOperation()
    {
        DoReferenceTransactionResponseType responseDoReferenceTransactionResponseType = new DoReferenceTransactionResponseType();

        try
        {
            // Create the DoReferenceTransactionReq object
            DoReferenceTransactionReq doReferenceTransaction = new DoReferenceTransactionReq();

            // Information about the payment.
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            // The total cost of the transaction to the buyer. If shipping cost and
            // tax charges are known, include them in this value. If not, this value
            // should be the current subtotal of the order.

            // If the transaction includes one or more one-time purchases, this field must be equal to
            // the sum of the purchases. Set this field to 0 if the transaction does
            // not include a one-time purchase such as when you set up a billing
            // agreement for a recurring payment that is not immediately charged.
            // When the field is set to 0, purchase-specific fields are ignored
            //
            // * `Currency ID` - You must set the currencyID attribute to one of the
            // 3-character currency codes for any of the supported PayPal
            // currencies.
            // * `Amount`
            BasicAmountType orderTotal = new BasicAmountType(CurrencyCodeType.USD, "3.00");
            paymentDetails.OrderTotal = orderTotal;

            // IPN URL
            // * PayPal Instant Payment Notification is a call back system that is initiated when a transaction is completed
            // * The transaction related IPN variables will be received on the call back URL specified in the request
            // * The IPN variables have to be sent back to the PayPal system for validation, upon validation PayPal will send a response string "VERIFIED" or "INVALID"
            // * PayPal would continuously resend IPN if a wrong IPN is sent
            paymentDetails.NotifyURL = "http://IPNhost";

            // `DoReferenceTransactionRequestDetails` takes mandatory params:
            //
            // * `Reference Id` - A transaction ID from a previous purchase, such as a
            // credit card charge using the DoDirectPayment API, or a billing
            // agreement ID.
            // * `Payment Action Code` - How you want to obtain payment. It is one of
            // the following values:
            // * Authorization
            // * Sale
            // * Order
            // * None
            // * `Payment Details`
            DoReferenceTransactionRequestDetailsType doReferenceTransactionRequestDetails
                = new DoReferenceTransactionRequestDetailsType("97U72738FY126561H", PaymentActionCodeType.SALE, paymentDetails);
            DoReferenceTransactionRequestType doReferenceTransactionRequest = new DoReferenceTransactionRequestType(doReferenceTransactionRequestDetails);
            doReferenceTransaction.DoReferenceTransactionRequest = doReferenceTransactionRequest;

            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

            // # API call
            // Invoke the DoReferenceTransaction method in service wrapper object
            responseDoReferenceTransactionResponseType = service.DoReferenceTransaction(doReferenceTransaction);

            if (responseDoReferenceTransactionResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "DoReferenceTransaction API Operation - ";
                acknowledgement += responseDoReferenceTransactionResponseType.Ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseDoReferenceTransactionResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // The final amount charged, including any shipping and taxes from your Merchant Profile
                    logger.Info("Amount : " + responseDoReferenceTransactionResponseType.DoReferenceTransactionResponseDetails.Amount.currencyID
                                + " " + responseDoReferenceTransactionResponseType.DoReferenceTransactionResponseDetails.Amount.value + "\n");
                    Console.WriteLine("Amount : " + responseDoReferenceTransactionResponseType.DoReferenceTransactionResponseDetails.Amount.currencyID
                                      + " " + responseDoReferenceTransactionResponseType.DoReferenceTransactionResponseDetails.Amount.value + "\n");
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseDoReferenceTransactionResponseType.Errors;
                    foreach (ErrorType error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.LongMessage);
                        Console.WriteLine("API Error Message : " + error.LongMessage + "\n");
                    }
                }
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return(responseDoReferenceTransactionResponseType);
    }