コード例 #1
0
 public RefundResponse Refund(RefundRequest RefundRequest)
 {
     return Refund(RefundRequest, null);
 }
コード例 #2
0
        /// <summary>
        /// Handle Refund API call
        /// </summary>
        /// <param name="context"></param>
        private void Refund(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            RefundRequest req = new RefundRequest(new RequestEnvelope("en_US"));
            // Set optional parameters
            if(parameters["receiverEmail"].Length > 0)
            {
                string[] amt = context.Request.Form.GetValues("receiverAmount");
                string[] receiverEmail = context.Request.Form.GetValues("receiverEmail");
                string[] phoneCountry = context.Request.Form.GetValues("phoneCountry");
                string[] phoneNumber = context.Request.Form.GetValues("phoneNumber");
                string[] phoneExtn = context.Request.Form.GetValues("phoneExtn");
                string[] primaryReceiver = context.Request.Form.GetValues("primaryReceiver");
                string[] invoiceId = context.Request.Form.GetValues("invoiceId");
                string[] paymentType = context.Request.Form.GetValues("paymentType");
                string[] paymentSubType = context.Request.Form.GetValues("paymentSubType");

                List<Receiver> receivers = new List<Receiver>();
                for(int i=0; i<amt.Length; i++) {
                    Receiver r = new Receiver(Decimal.Parse(amt[i]));
                    r.email = receiverEmail[i];
                    r.primary = Boolean.Parse(primaryReceiver[i]);
                    if(invoiceId[i] != "") {
                        r.invoiceId = invoiceId[i];
                    }
                    if(paymentType[i] != "") {
                        r.paymentType = paymentType[i];
                    }
                    if(paymentSubType[i] != "") {
                        r.paymentSubType = paymentSubType[i];
                    }
                    if(phoneCountry[i] != "" && phoneNumber[i] != "") {
                        r.phone = new PhoneNumberType(phoneCountry[i], phoneNumber[i]);
                        if(phoneExtn[i] != "") {
                            r.phone.extension = phoneExtn[i];
                        }
                    }
                    receivers.Add(r);
                }
                req.receiverList = new ReceiverList(receivers);
            }
            if(parameters["currencyCode"] != "") {
                req.currencyCode = parameters["currencyCode"];
            }
            if(parameters["payKey"] != "") {
                req.payKey = parameters["payKey"];
            }
            if(parameters["transactionId"] != "") {
                req.transactionId = parameters["transactionId"];
            }
            if(parameters["trackingId"] != "") {
                req.trackingId = parameters["trackingId"];
            }

            // All set. Fire the request
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            RefundResponse resp = null;
            try
            {
                resp = service.Refund(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("Currency code", resp.currencyCode);
                int idx = 1;
                foreach (RefundInfo refund in resp.refundInfoList.refundInfo)
                {
                    keyResponseParams.Add("Refund receiver " + idx, refund.receiver.email);
                    keyResponseParams.Add("Refund amount " + idx, refund.receiver.amount.ToString());
                    keyResponseParams.Add("Refund status " + idx, refund.refundStatus);

                    //Selenium Test Case
                    keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
                }
            }
            displayResponse(context, "Refund", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
コード例 #3
0
        /**
         *
         */
        public RefundResponse Refund(RefundRequest RefundRequest, string apiUsername)
        {
            string resp = call("Refund", RefundRequest.toNVPString(""), apiUsername);

            NVPUtil util = new NVPUtil();
            return new RefundResponse(util.parseNVPString(resp), "");
        }
コード例 #4
0
	 	/// <summary>
		/// 
	 	/// </summary>
		///<param name="refundRequest"></param>
		///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> 
	 	public RefundResponse Refund(RefundRequest refundRequest, ICredential credential)
	 	{	 			 		
			IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, refundRequest.ToNVPString(string.Empty), ServiceName, "Refund", credential);
	   	 	((PlatformAPICallPreHandler) apiCallPreHandler).SDKName = SDKName;
			((PlatformAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion;
			((PlatformAPICallPreHandler) apiCallPreHandler).PortName = "AdaptivePayments";

			NVPUtil util = new NVPUtil();
			return RefundResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1);
			
	 	}
コード例 #5
0
	 	/// <summary> 
		/// 
	 	/// </summary>
		///<param name="refundRequest"></param>
	 	
	 	public RefundResponse Refund(RefundRequest refundRequest)
	 	{
	 		return Refund(refundRequest,(string) null);
	 	}
        /// <summary>
        /// Handle Refund API call
        /// </summary>
        /// <param name="contextHttp"></param>
        private void Refund(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. 
            RefundRequest request = new RefundRequest(new RequestEnvelope("en_US"));

            // Set optional parameters
            if(parameters["receiverEmail"].Length > 0) 
            {
                //(Required) Amount to be paid to the receiver
                string[] amt = contextHttp.Request.Form.GetValues("receiverAmount");

                // Receiver's email address. This address can be unregistered with paypal.com.
                // If so, a receiver cannot claim the payment until a PayPal account is linked
                // to the email address. The PayRequest must pass either an email address or a phone number. 
                // Maximum length: 127 characters
                string[] receiverEmail = contextHttp.Request.Form.GetValues("receiverEmail");

                //Telephone country code 
                string[] phoneCountry = contextHttp.Request.Form.GetValues("phoneCountry");

                // A type to specify the receiver's phone number.
                // The PayRequest must pass either an email address or a phone number as the payment receiver.
                string[] phoneNumber = contextHttp.Request.Form.GetValues("phoneNumber");

                //Telephone extension
                string[] phoneExtn = contextHttp.Request.Form.GetValues("phoneExtn");

                // (Optional) Whether this receiver is the primary receiver, 
                // which makes the payment a chained payment.You can specify at most one primary receiver. 
                // Omit this field for simple and parallel payments. Allowable values are:
                //  true – Primary receiver
                //  false – Secondary receiver (default)
                string[] primaryReceiver = contextHttp.Request.Form.GetValues("primaryReceiver");

                // (Optional) Your own invoice or tracking number.
                //Character length and limitations: 127 single-byte alphanumeric characters
                string[] invoiceId = contextHttp.Request.Form.GetValues("invoiceId");

                // (Optional) The transaction type for the payment. Allowable values are:
                // GOODS – This is a payment for non-digital goods
                // SERVICE – This is a payment for services (default)
                // PERSONAL – This is a person-to-person payment
                // CASHADVANCE – This is a person-to-person payment for a cash advance
                // DIGITALGOODS – This is a payment for digital goods
                // BANK_MANAGED_WITHDRAWAL – This is a person-to-person payment for bank withdrawals, available only with special permission.
                string[] paymentType = contextHttp.Request.Form.GetValues("paymentType");
                //(Optional) The transaction subtype for the payment. 
                string[] paymentSubType = contextHttp.Request.Form.GetValues("paymentSubType");

	            List<Receiver> receivers = new List<Receiver>();
	            for(int i=0; i<amt.Length; i++) {
                    Receiver r = new Receiver(Convert.ToDecimal(amt[i]));
		            r.email = receiverEmail[i];
                    r.primary = Convert.ToBoolean(primaryReceiver[i]);
		            if(invoiceId[i] != string.Empty) {
			            r.invoiceId = invoiceId[i];
		            }
		            if(paymentType[i] != string.Empty) {
			            r.paymentType = paymentType[i];
		            }
		            if(paymentSubType[i] != string.Empty) {
			            r.paymentSubType = paymentSubType[i];
		            }
		            if(phoneCountry[i] != string.Empty && phoneNumber[i] != string.Empty) {
			            r.phone = new PhoneNumberType(phoneCountry[i], phoneNumber[i]);
			            if(phoneExtn[i] != string.Empty) {
				            r.phone.extension = phoneExtn[i];
			            }
		            }
                    receivers.Add(r);
	            }
	            request.receiverList = new ReceiverList(receivers);
            }

            // PayPal uses 3-character ISO-4217 codes for specifying currencies in fields and variables.  
            if(parameters["currencyCode"] != string.Empty) {
	            request.currencyCode = parameters["currencyCode"];
            }

            // The key used to create the payment that you want to refund
            if(parameters["payKey"] != string.Empty) {
	            request.payKey = parameters["payKey"];
            }

            // A PayPal transaction ID associated with the receiver whose payment 
            // you want to refund to the sender. Use field name characters exactly as shown.
            if(parameters["transactionId"] != string.Empty) {
	            request.transactionId = parameters["transactionId"];
            }

            // The tracking ID associated with the payment that you want to refund
            if(parameters["trackingId"] != string.Empty) {
                request.trackingId = parameters["trackingId"];
            }            
          
            AdaptivePaymentsService service = null;
            RefundResponse 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.Refund(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))
            {
                responseValues.Add("Currency code", response.currencyCode);
                int idx = 1;
                foreach (RefundInfo refund in response.refundInfoList.refundInfo)
                {
                    //Receiver's email address.Maximum length: 127 characters
                    responseValues.Add("Refund receiver " + idx, refund.receiver.email);
                    // Amount to be refunded to the receiver.
                    responseValues.Add("Refund amount " + idx, refund.receiver.amount.ToString());
                    // Status of the refund. It is one of the following values:
                    //   REFUNDED – Refund successfully completed
                    //   REFUNDED_PENDING – Refund awaiting transfer of funds; for example, a refund paid by eCheck.
                    //   NOT_PAID – Payment was never made; therefore, it cannot be refunded.
                    //   ALREADY_REVERSED_OR_REFUNDED – Request rejected because the refund was already made, or the payment was reversed prior to this request.
                    //   NO_API_ACCESS_TO_RECEIVER – Request cannot be completed because you do not have third-party access from the receiver to make the refund.
                    //   REFUND_NOT_ALLOWED – Refund is not allowed.
                    //   INSUFFICIENT_BALANCE – Request rejected because the receiver from which the refund is to be paid does not have sufficient funds or the funding source cannot be used to make a refund.
                    //   AMOUNT_EXCEEDS_REFUNDABLE – Request rejected because you attempted to refund more than the remaining amount of the payment; call the PaymentDetails API operation to determine the amount already refunded.
                    //   PREVIOUS_REFUND_PENDING – Request rejected because a refund is currently pending for this part of the payment
                    //   NOT_PROCESSED – Request rejected because it cannot be processed at this time
                    //   REFUND_ERROR – Request rejected because of an internal error
                    //   PREVIOUS_REFUND_ERROR – Request rejected because another part of this refund caused an internal error.
                    responseValues.Add("Refund status " + idx, refund.refundStatus);

                    
                    responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());
                }
            }
            Display(contextHttp, "Refund", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
        }
コード例 #7
0
 /**
   *AUTO_GENERATED
  	  */
 public RefundResponse Refund(RefundRequest refundRequest, string apiUserName)
 {
     string response = Call("Refund", refundRequest.ToNVPString(""), apiUserName);
     NVPUtil util = new NVPUtil();
     return RefundResponse.CreateInstance(util.ParseNVPString(response), "", -1);
 }
コード例 #8
0
    // # Refund API Operation
    // Use the Refund API operation to refund all or part of a payment. You can specify the amount of the refund and identify the accounts to receive the refund by the payment key or tracking ID, and optionally, by transaction ID or the receivers of the original payment. 
    public RefundResponse RefundAPIOperation()
    {
        // Create the RefundResponse object
        RefundResponse responseRefund = new RefundResponse();

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

            // RefundRequest which takes,
            // `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            RefundRequest requestRefund = new RefundRequest(envelopeRequest);

            // You must specify either,
            //
            // * `Pay Key` - The pay key that identifies the payment for which you
            // want to retrieve details. This is the pay key returned in the
            // PayResponse message.
            // * `Transaction ID` - The PayPal transaction ID associated with the
            // payment. The IPN message associated with the payment contains the
            // transaction ID.
            // `requestRefund.transactionId = transactionId`
            // * `Tracking ID` - The tracking ID that was specified for this payment
            // in the PayRequest message.
            // `requestRefund.trackingId = trackingId`
            requestRefund.payKey = "AP-86H50830VE600922B";

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

            // # API call
            // Invoke the Refund method in service wrapper object
            responseRefund = service.Refund(requestRefund);

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

                // # Success values
                if (responseRefund.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // List of refunds associated with the payment.
                    IEnumerator<RefundInfo> iterator = responseRefund.refundInfoList.refundInfo.GetEnumerator();

                    while (iterator.MoveNext())
                    {
                        // Represents the refund attempt made to a receiver of a
                        // PayRequest.
                        RefundInfo refundInfo = iterator.Current;

                        // Status of the refund. It is one of the following values:
                        //
                        // * REFUNDED - Refund successfully completed
                        // * REFUNDED_PENDING - Refund awaiting transfer of funds; for
                        // example, a refund paid by eCheck.
                        // * NOT_PAID - Payment was never made; therefore, it cannot
                        // be refunded.
                        // * ALREADY_REVERSED_OR_REFUNDED - Request rejected because
                        // the refund was already made, or the payment was reversed
                        // prior to this request.
                        // * NO_API_ACCESS_TO_RECEIVER - Request cannot be completed
                        // because you do not have third-party access from the
                        // receiver to make the refund.
                        // * REFUND_NOT_ALLOWED - Refund is not allowed.
                        // * INSUFFICIENT_BALANCE - Request rejected because the
                        // receiver from which the refund is to be paid does not
                        // have sufficient funds or the funding source cannot be
                        // used to make a refund.
                        // * AMOUNT_EXCEEDS_REFUNDABLE - Request rejected because you
                        // attempted to refund more than the remaining amount of the
                        // payment; call the PaymentDetails API operation to
                        // determine the amount already refunded.
                        // * PREVIOUS_REFUND_PENDING - Request rejected because a
                        // refund is currently pending for this part of the payment
                        // * NOT_PROCESSED - Request rejected because it cannot be
                        // processed at this time
                        // * REFUND_ERROR - Request rejected because of an internal
                        // error
                        // * PREVIOUS_REFUND_ERROR - Request rejected because another
                        // part of this refund caused an internal error.
                        logger.Info("Refund Status : " + refundInfo.refundStatus + "\n");
                        Console.WriteLine("Refund Status : " + refundInfo.refundStatus + "\n");
                    }
                }
                // # Error Values
                else
                {
                    List<ErrorData> errorMessages = responseRefund.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 responseRefund;
    }