Esempio n. 1
0
        /**
         *
         */
        public ExecutePaymentResponse ExecutePayment(ExecutePaymentRequest ExecutePaymentRequest, string apiUsername)
        {
            string resp = call("ExecutePayment", ExecutePaymentRequest.toNVPString(""), apiUsername);

            NVPUtil util = new NVPUtil();
            return new ExecutePaymentResponse(util.parseNVPString(resp), "");
        }
Esempio n. 2
0
 public ExecutePaymentResponse ExecutePayment(ExecutePaymentRequest ExecutePaymentRequest)
 {
     return ExecutePayment(ExecutePaymentRequest, null);
 }
        /// <summary>
        /// Handle ExecutePayment API call
        /// </summary>
        /// <param name="context"></param>
        private void ExecutePayment(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            ExecutePaymentRequest req = new ExecutePaymentRequest(new RequestEnvelope("en_US"), parameters["payKey"]);

            //Fix for release
            req.fundingPlanId = parameters["fundingPlanId"];

            // All set. Fire the request
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            ExecutePaymentResponse resp = null;
            try
            {
                resp = service.ExecutePayment(req);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }

            // Display response values.
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(resp.responseEnvelope.ack == AckCode.FAILURE) &&
                !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {
                keyResponseParams.Add("Payment exeucution status", resp.paymentExecStatus);

                //Selenium Test Case
                keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
            }
            displayResponse(context, "ExecutePayment", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
    // # ExecutePayment API Operation
    // The ExecutePayment API operation lets you execute a payment set up with the Pay API operation with the actionType CREATE. To pay receivers identified in the Pay call, set the pay key from the PayResponse message in the ExecutePaymentRequest message. 
    public ExecutePaymentResponse ExecutePaymentAPIOperation()
    {
        // Create the ExecutePaymentResponse object
        ExecutePaymentResponse responseExecutePayment = new ExecutePaymentResponse();

        try
        {
            // # ExecutePaymentRequest
            // The code for the language in which errors are returned
            RequestEnvelope envelopeRequest = new RequestEnvelope();
            envelopeRequest.errorLanguage = "en_US";

            // ExecutePaymentRequest which takes,
            //
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Pay Key` - The pay key that identifies the payment for which you
            // want to set payment options. This is the pay key returned in the
            // PayResponse message. Action Type in PayRequest must be `CREATE`
            ExecutePaymentRequest requestExecutePayment = new ExecutePaymentRequest(envelopeRequest, "AP-1VB65877N5917862M");

            // The ID of the funding plan from which to make this payment.
            requestExecutePayment.fundingPlanId = "0";

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

            // # API call           
            // Invoke the ExecutePayment method in service wrapper object
            responseExecutePayment = service.ExecutePayment(requestExecutePayment);

            if (responseExecutePayment != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "ExecutePayment API operation - ";
                acknowledgement += responseExecutePayment.responseEnvelope.ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseExecutePayment.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // 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
                    // * 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
                    logger.Info("Payment Execution Status: " + responseExecutePayment.paymentExecStatus + "\n");
                    Console.WriteLine("Payment Execution Status : " + responseExecutePayment.paymentExecStatus + "\n");

                }
                // # Error Values 
                else
                {
                    List<ErrorData> errorMessages = responseExecutePayment.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.message);
                        Console.WriteLine("API Error Message : " + error.message + "\n");
                    }
                }
            }
        }
        // # Exception log    
        catch (System.Exception ex)
        {
            // Log the exception message       
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return responseExecutePayment;
    }
	 	/// <summary>
		/// 
	 	/// </summary>
		///<param name="executePaymentRequest"></param>
		///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> 
	 	public ExecutePaymentResponse ExecutePayment(ExecutePaymentRequest executePaymentRequest, ICredential credential)
	 	{	 			 		
			IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, executePaymentRequest.ToNVPString(string.Empty), ServiceName, "ExecutePayment", credential);
	   	 	((PlatformAPICallPreHandler) apiCallPreHandler).SDKName = SDKName;
			((PlatformAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion;
			((PlatformAPICallPreHandler) apiCallPreHandler).PortName = "AdaptivePayments";

			NVPUtil util = new NVPUtil();
			return ExecutePaymentResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1);
			
	 	}
	 	/// <summary> 
		/// 
	 	/// </summary>
		///<param name="executePaymentRequest"></param>
	 	
	 	public ExecutePaymentResponse ExecutePayment(ExecutePaymentRequest executePaymentRequest)
	 	{
	 		return ExecutePayment(executePaymentRequest,(string) null);
	 	}
        /// <summary>
        /// Handle ExecutePayment API call
        /// </summary>
        /// <param name="contextHttp"></param>
        private void ExecutePayment(HttpContext contextHttp)
        {
            NameValueCollection parameters = contextHttp.Request.Params;

            // error language : (Required) RFC 3066 language in which error 
            // messages are returned; by default it is en_US, which is the only language currently supported. 
            // paykey : (Optional) The pay key that identifies the payment to be executed. 
            // This is the pay key returned in the PayResponse message. 
            ExecutePaymentRequest request = new ExecutePaymentRequest(new RequestEnvelope("en_US"), parameters["payKey"]);

            // (Optional) The ID of the funding plan from which to make this payment. 
            request.fundingPlanId = parameters["fundingPlanId"];
            
            AdaptivePaymentsService service = null;
            ExecutePaymentResponse response = null;
            try
            {
                // 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();

                // Creating service wrapper object to make an API call and loading
                // configuration map for your credentials and endpoint
                service = new AdaptivePaymentsService(configurationMap);
                response = service.ExecutePayment(request);
            }
            catch (System.Exception e)
            {
                contextHttp.Response.Write(e.Message);
                return;
            }

            Dictionary<string, string> responseValues = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
                !(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {
                //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
                // 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
                // Important: You must test the value of paymentExecStatus for an error even if 
                // responseEnvelope.ack is Success. If the PaymentExecStatus is ERROR, 
                // the Pay Key can no longer be used. 
                responseValues.Add("Payment exeucution status", response.paymentExecStatus);

                
                responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());
            }
            Display(contextHttp, "ExecutePayment", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
        }
Esempio n. 8
0
 /**
   *AUTO_GENERATED
  	  */
 public ExecutePaymentResponse ExecutePayment(ExecutePaymentRequest executePaymentRequest, string apiUserName)
 {
     string response = Call("ExecutePayment", executePaymentRequest.ToNVPString(""), apiUserName);
     NVPUtil util = new NVPUtil();
     return ExecutePaymentResponse.CreateInstance(util.ParseNVPString(response), "", -1);
 }
        public ActionResult paypalPaymentExecute(string id)
        {
            var api = GoPlayApi.Instance;
            var transaction = api.GetGcoinTransaction(id);
            if (transaction.HasData)
            {
                var headers = PaypalHelper.GetHeader();

                RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");

                ExecutePaymentRequest executePayment = new ExecutePaymentRequest
                {
                    requestEnvelope = requestEnvelope,
                    payKey = transaction.Data.pay_key
                };

                AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(headers);
                ExecutePaymentResponse executePaymentResponse = adaptivePaymentsService.ExecutePayment(executePayment);

                if (executePaymentResponse.responseEnvelope.ack.Value.ToString().ToLower() == "success" && executePaymentResponse.paymentExecStatus == "COMPLETED" && executePaymentResponse.error[0].errorId.Value.ToString() == "580022")
                {
                    transaction.Data.status = "success";
                    //update trans

                    api.UpdateGCoinTransaction(transaction.Data);

                    logger.Fatal("update payment success");

                    this.Flash("Transaction is successful.", FlashLevel.Success);
                    return Json(new { success = true });
                }
                else
                {
                    var error_msg = executePaymentResponse.error[0].message;
                    logger.Fatal(error_msg);

                    this.Flash(error_msg, FlashLevel.Error);
                }
                return RedirectToAction("gcoinTransactionIndex", "paypal");
            }
            return Json(new { success = false });
        }