public void Valid_payment_successfull_validation()
        {
            //arrange
            var service = new AdaptivePaymentsService(GetConfigiration());
            var request = CreatePayRequest();

            //act
            var payResponse = service.Pay(request);
            var setPaymentOptionsResponse = service.SetPaymentOptions(new SetPaymentOptionsRequest {
                payKey = payResponse.payKey, senderOptions = new SenderOptions {
                    referrerCode = "Virto_SP"
                }, requestEnvelope = new RequestEnvelope {
                    errorLanguage = "en_US"
                }
            });

            // var executePaymentResponse = service.ExecutePayment(new ExecutePaymentRequest { payKey = payResponse.payKey, actionType = "PAY", requestEnvelope = new RequestEnvelope { errorLanguage = "en_US" } });

            //assert
            Assert.Equal("", GetErrors(payResponse.error));
            Assert.Equal("", GetErrors(setPaymentOptionsResponse.error));
            // Assert.Equal("", GetErrors(executePaymentResponse.error));

            output.WriteLine(payResponse.paymentExecStatus + ". PayKey: " + payResponse.payKey);
            output.WriteLine("Activate " + string.Format(SandboxPaypalBaseUrlFormat, payResponse.payKey));
        }
    // # SetPaymentOptions API Operation
    // You use the SetPaymentOptions API operation to specify settings for a payment of the actionType CREATE. This actionType is specified in the PayRequest message.
    public SetPaymentOptionsResponse SetPaymentOptionsAPIOperation()
    {
        // Create the SetPaymentOptionsResponse object
        SetPaymentOptionsResponse responseSetPaymentOptions = new SetPaymentOptionsResponse();

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

            // SetPaymentOptionsRequest 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`
            SetPaymentOptionsRequest requestSetPaymentOptions = new SetPaymentOptionsRequest(envelopeRequest, "AP-1VB65877N5917862M");

            // Specifies display items in payment flows and emails.
            DisplayOptions displayOptions = new DisplayOptions();

            // The business name to display
            // The name cannot exceed 128 characters
            displayOptions.businessName             = "Toy Shop";
            requestSetPaymentOptions.displayOptions = displayOptions;

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

            // # API call
            // Invoke the SetPaymentOptions method in service wrapper object
            responseSetPaymentOptions = service.SetPaymentOptions(requestSetPaymentOptions);

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

                // # Success values
                if (responseSetPaymentOptions.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    responseSetPaymentOptions.responseEnvelope.ack.ToString();
                }
                // # Error Values
                else
                {
                    List <ErrorData> errorMessages = responseSetPaymentOptions.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(responseSetPaymentOptions);
    }
Beispiel #3
0
        /// <summary>
        /// Handle SetPaymentOptions API call
        /// </summary>
        /// <param name="context"></param>
        private void SetPaymentOptions(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            SetPaymentOptionsRequest req = new SetPaymentOptionsRequest(
                    new RequestEnvelope("en_US"), parameters["payKey"]);
            if (parameters["institutionId"] != "")
            {
                req.initiatingEntity = new InitiatingEntity();
                req.initiatingEntity.institutionCustomer = new InstitutionCustomer(
                    parameters["institutionId"], parameters["firstName"], 
                    parameters["lastName"], parameters["displayName"], 
                    parameters["institutionCustomerId"], parameters["countryCode"]);
                if (parameters["email"] != "")
                {
                    req.initiatingEntity.institutionCustomer.email = parameters["email"];
                }
            }
            if (parameters["emailHeaderImageUrl"] != "" || parameters["emailMarketingImageUrl"] != ""
                || parameters["headerImageUrl"] != "" || parameters["businessName"] != "")
            {
                req.displayOptions = new DisplayOptions();
                if (parameters["emailHeaderImageUrl"] != "" )
                    req.displayOptions.emailHeaderImageUrl = parameters["emailHeaderImageUrl"];
                if (parameters["emailMarketingImageUrl"] != "")
                    req.displayOptions.emailMarketingImageUrl = parameters["emailMarketingImageUrl"];
                if(parameters["headerImageUrl"] != "" )
                    req.displayOptions.headerImageUrl = parameters["headerImageUrl"];
                if(parameters["businessName"] != "")
                    req.displayOptions.businessName = parameters["businessName"];
            }
            if (parameters["shippingAddressId"] != "")
            {
                req.shippingAddressId = parameters["shippingAddressId"];
            }
            if (parameters["requireShippingAddressSelection"] != "" || parameters["referrerCode"] != "")
            {
                req.senderOptions = new SenderOptions();
                if (parameters["requireShippingAddressSelection"] != "")
                    req.senderOptions.requireShippingAddressSelection = 
                        Boolean.Parse(parameters["requireShippingAddressSelection"]);
                if (parameters["referrerCode"] != "")
                    req.senderOptions.referrerCode = parameters["referrerCode"];
            }
            req.receiverOptions = new List<ReceiverOptions>();
            ReceiverOptions receiverOption = new ReceiverOptions();
            req.receiverOptions.Add(receiverOption);
            if (parameters["description"] != "")
                receiverOption.description = parameters["description"];
            if (parameters["customId"] != "")
                receiverOption.customId = parameters["customId"];

            string[] name = context.Request.Form.GetValues("name");
            string[] identifier = context.Request.Form.GetValues("identifier");
            string[] price = context.Request.Form.GetValues("price");
            string[] itemPrice = context.Request.Form.GetValues("itemPrice");
            string[] itemCount = context.Request.Form.GetValues("itemCount");
            if (name.Length > 0 && name[0] != "")
            {
                receiverOption.invoiceData = new InvoiceData();
                for (int j = 0; j < name.Length; j++)
                {
                    InvoiceItem item = new InvoiceItem();
                    if (name[j] != "")
                        item.name = name[j];
                    if (identifier[j] != "")
                        item.identifier = identifier[j];
                    if (price[j] != "")
                        item.price = Decimal.Parse(price[j]);
                    if (itemPrice[j] != "")
                        item.itemPrice = Decimal.Parse(itemPrice[j]);
                    if (itemCount[j] != "")
                        item.itemCount = Int32.Parse(itemCount[j]);
                    receiverOption.invoiceData.item.Add(item);
                }
                if (parameters["totalTax"] != "")
                    receiverOption.invoiceData.totalTax = Decimal.Parse(parameters["totalTax"]);
                if (parameters["totalShipping"] != "")
                    receiverOption.invoiceData.totalShipping = Decimal.Parse(parameters["totalShipping"]);
            }
            if (parameters["emailIdentifier"] != "" ||
                (parameters["phoneCountry"] != "" && parameters["phoneNumber"] != ""))
            {
                receiverOption.receiver = new ReceiverIdentifier();
                if(parameters["emailIdentifier"] != "")
                    receiverOption.receiver.email = parameters["emailIdentifier"];
                if (parameters["phoneCountry"] != "" && parameters["phoneNumber"] != "")
                {
                    receiverOption.receiver.phone = 
                        new PhoneNumberType(parameters["phoneCountry"], parameters["phoneNumber"]);
                    if (parameters["phoneExtn"] != "")
                        receiverOption.receiver.phone.extension = parameters["phoneExtn"];
                }
            }
            if (parameters["receiverReferrerCode"] != "")
                receiverOption.referrerCode = parameters["receiverReferrerCode"];

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

            // Display response values. 
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();            
            displayResponse(context, "SetPaymentOptions", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, null);
        }
Beispiel #4
0
        public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context)
        {
            var retVal = new ProcessPaymentResult();

            if (context.Store == null)
            {
                throw new NullReferenceException("no store with this id");
            }

            if (!(!string.IsNullOrEmpty(context.Store.SecureUrl) || !string.IsNullOrEmpty(context.Store.Url)))
            {
                throw new NullReferenceException("store must specify Url or SecureUrl property");
            }

            var url = string.Empty;

            if (!string.IsNullOrEmpty(context.Store.SecureUrl))
            {
                url = context.Store.SecureUrl;
            }
            else
            {
                url = context.Store.Url;
            }

            var config = GetConfigMap();

            var service = new AdaptivePaymentsService(config);

            var request = CreatePaypalRequest(context.Order, context.Payment, url);

            var payResponse = service.Pay(request);
            var setPaymentOptionsResponse = service.SetPaymentOptions(new SetPaymentOptionsRequest {
                payKey = payResponse.payKey, senderOptions = new SenderOptions {
                    referrerCode = "Virto_SP"
                }
            });
            var executePaymentResponse = service.ExecutePayment(new ExecutePaymentRequest {
                payKey = payResponse.payKey, actionType = "PAY", requestEnvelope = new RequestEnvelope {
                    errorLanguage = "en_US"
                }
            });

            if (executePaymentResponse.error != null && executePaymentResponse.error.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (var error in executePaymentResponse.error)
                {
                    sb.AppendLine(error.message);
                }
                retVal.Error            = sb.ToString();
                retVal.NewPaymentStatus = PaymentStatus.Voided;
            }
            else
            {
                retVal.OuterId   = payResponse.payKey;
                retVal.IsSuccess = true;
                var redirectBaseUrl = GetBaseUrl(Mode);
                retVal.RedirectUrl      = string.Format(redirectBaseUrl, retVal.OuterId);
                retVal.NewPaymentStatus = PaymentStatus.Pending;
            }

            return(retVal);
        }