public static NameValueCollection CreateSetExpressCheckoutMetadata(
            SetExpressCheckoutPayload payload) {

            return new NameValueCollection {
                {"METHOD", payload.Method},
                {"VERSION", payload.Version},
                {"USER", payload.User},
                {"PWD", payload.Password},
                {"SIGNATURE", payload.Signature},
                {"SUBJECT", payload.Subject},
                {"LOCALECODE", payload.LocaleCode},
                {"RETURNURL", payload.ReturnUrl},
                {"CANCELURL", payload.CancelUrl},
                {"REQBILLINGADDRESS", payload.RequireBillingAddress},
                {"NOSHIPPING", payload.NoShipping},
                {"PAYMENTREQUEST_0_PAYMENTACTION", payload.Action}, {
                    "PAYMENTREQUEST_0_AMT",
                    payload.Amount.ToString(CultureInfo.InvariantCulture)
                },
                {"PAYMENTREQUEST_0_CURRENCYCODE", payload.CurrencyCode}, {
                    "MAXAMT", payload.Amount.ToString(CultureInfo.InvariantCulture)
                },
                {"L_PAYMENTREQUEST_0_NAME0", payload.PaymentRequestName},
                {"L_PAYMENTREQUEST_0_DESC0", payload.PaymentRequestDescription}, {
                    "L_PAYMENTREQUEST_0_AMT0",
                    payload.Amount.ToString(CultureInfo.InvariantCulture)
                },
                {"L_PAYMENTREQUEST_0_QTY0", payload.PaymentRequestQuantity}
            };
        }
Exemple #2
0
 public static NameValueCollection CreateSetExpressCheckoutMetadata(
     SetExpressCheckoutPayload payload)
 {
     return(new NameValueCollection {
         { "METHOD", payload.Method },
         { "VERSION", payload.Version },
         { "USER", payload.User },
         { "PWD", payload.Password },
         { "SIGNATURE", payload.Signature },
         { "SUBJECT", payload.Subject },
         { "LOCALECODE", payload.LocaleCode },
         { "RETURNURL", payload.ReturnUrl },
         { "CANCELURL", payload.CancelUrl },
         { "REQBILLINGADDRESS", payload.RequireBillingAddress },
         { "NOSHIPPING", payload.NoShipping },
         { "PAYMENTREQUEST_0_PAYMENTACTION", payload.Action }, {
             "PAYMENTREQUEST_0_AMT",
             payload.Amount.ToString(CultureInfo.InvariantCulture)
         },
         { "PAYMENTREQUEST_0_CURRENCYCODE", payload.CurrencyCode }, {
             "MAXAMT", payload.Amount.ToString(CultureInfo.InvariantCulture)
         },
         { "L_PAYMENTREQUEST_0_NAME0", payload.PaymentRequestName },
         { "L_PAYMENTREQUEST_0_DESC0", payload.PaymentRequestDescription }, {
             "L_PAYMENTREQUEST_0_AMT0",
             payload.Amount.ToString(CultureInfo.InvariantCulture)
         },
         { "L_PAYMENTREQUEST_0_QTY0", payload.PaymentRequestQuantity }
     });
 }
        /// <summary>
        ///     Executes PayPal's <b>SetExpressCheckout</b> function in order to
        ///     return a PayPal Access Token.
        /// </summary>
        /// <param name="payload">
        ///     Metadata necessary to facilitate a successful
        ///     <b>SetExpressCheckout</b> call. Payload will be converted to key-value
        ///     format.
        /// </param>
        /// <param name="encoding">Text encoding to apply during byte-to-text conversion.</param>
        /// <param name="expressCheckoutURI">Default PayPal ExpressCheckout HTTP URI.</param>
        /// <returns>Raw metadata, in key-value format, containing a PayPal Access Token.</returns>
        public string SetExpressCheckout(SetExpressCheckoutPayload payload,
            Encoding encoding, string expressCheckoutURI) {

            var setExpressCheckoutMetadata =
                ExpressCheckoutMetadataFactory.CreateSetExpressCheckoutMetadata(
                    payload);

            using (var webClient = new WebClient()) {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var response = webClient.UploadValues(expressCheckoutURI,
                    setExpressCheckoutMetadata);
                return encoding.GetString(response);
            }
        }
        /// <summary>
        ///     Executes PayPal's <b>SetExpressCheckout</b> function in order to
        ///     return a PayPal Access Token.
        /// </summary>
        /// <param name="payload">
        ///     Metadata necessary to facilitate a successful
        ///     <b>SetExpressCheckout</b> call. Payload will be converted to key-value
        ///     format.
        /// </param>
        /// <param name="encoding">Text encoding to apply during byte-to-text conversion.</param>
        /// <param name="expressCheckoutURI">Default PayPal ExpressCheckout HTTP URI.</param>
        /// <returns>Raw metadata, in key-value format, containing a PayPal Access Token.</returns>
        public string SetExpressCheckout(SetExpressCheckoutPayload payload,
            Encoding encoding, string expressCheckoutURI) {

            var setExpressCheckoutMetadata =
                ExpressCheckoutMetadataFactory.CreateSetExpressCheckoutMetadata(
                    payload);

            using (var webClient = new WebClient()) {

                var response = webClient.UploadValues(expressCheckoutURI,
                    setExpressCheckoutMetadata);
                return encoding.GetString(response);
            }
        }
Exemple #5
0
        /// <summary>
        ///     Executes PayPal's <b>SetExpressCheckout</b> function in order to
        ///     return a PayPal Access Token.
        /// </summary>
        /// <param name="payload">
        ///     Metadata necessary to facilitate a successful
        ///     <b>SetExpressCheckout</b> call. Payload will be converted to key-value
        ///     format.
        /// </param>
        /// <param name="encoding">Text encoding to apply during byte-to-text conversion.</param>
        /// <param name="expressCheckoutURI">Default PayPal ExpressCheckout HTTP URI.</param>
        /// <returns>Raw metadata, in key-value format, containing a PayPal Access Token.</returns>
        public string SetExpressCheckout(SetExpressCheckoutPayload payload,
                                         Encoding encoding, string expressCheckoutURI)
        {
            var setExpressCheckoutMetadata =
                ExpressCheckoutMetadataFactory.CreateSetExpressCheckoutMetadata(
                    payload);

            using (var webClient = new WebClient()) {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var response = webClient.UploadValues(expressCheckoutURI,
                                                      setExpressCheckoutMetadata);
                return(encoding.GetString(response));
            }
        }
        /// <summary>
        ///     <see cref="SetExpressCheckout" /> asynchronous equivalent.
        ///     <seealso cref="SetExpressCheckout" />
        /// </summary>
        /// <param name="payload">
        ///     Metadata necessary to facilitate a successful
        ///     <b>SetExpressCheckout</b> call. Payload will be converted to key-value
        ///     format.
        /// </param>
        /// <param name="encoding">Text encoding to apply during byte-to-text conversion.</param>
        /// <param name="expressCheckoutURI">Default PayPal ExpressCheckout HTTP URI.</param>
        /// <returns>
        ///     A <see cref="Task" /> of <see cref="string" />, representing raw
        ///     metadata, in key-value format, containing a PayPal Access Token.
        /// </returns>
        public async Task<string> SetExpressCheckoutAsync(
            SetExpressCheckoutPayload payload,
            Encoding encoding, string expressCheckoutURI) {

            var setExpressCheckoutMetadata =
                ExpressCheckoutMetadataFactory.CreateSetExpressCheckoutMetadata(
                    payload);

            using (var webClient = new WebClient()) {

                var response =
                    await webClient.UploadValuesTaskAsync(expressCheckoutURI,
                        setExpressCheckoutMetadata);
                return encoding.GetString(response);
            }
        }