示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            WebPaymentAPI ws = new WebPaymentAPI();

            string amount    = ((TextBox)(Page.PreviousPage.FindControl("doWebPayment").FindControl("amount"))).Text;
            string currency  = ((DropDownList)(Page.PreviousPage.FindControl("doWebPayment").FindControl("currency"))).Text;
            string reference = ((TextBox)(Page.PreviousPage.FindControl("doWebPayment").FindControl("ref"))).Text;

            payment.amount         = amount;
            payment.currency       = currency;
            payment.action         = Resources.Resource.PAYMENT_ACTION;
            payment.mode           = Resources.Resource.PAYMENT_MODE;
            payment.contractNumber = Resources.Resource.CONTRACT_NUMBER;


            order.@ref     = reference;
            order.amount   = amount;
            order.currency = currency;

            order.date = (DateTime.Now).ToString("dd/MM/yyyy HH:mm", ci);

            selectedCrontractList.SetValue(Resources.Resource.CONTRACT_NUMBER_LIST, 0);
            recurring = null;
            buyer     = null;

            //PROXY
            if (Resources.Resource.PROXY_HOST != "" && Resources.Resource.PROXY_PORT != "")
            {
                ws.Proxy = new System.Net.WebProxy(Resources.Resource.PROXY_HOST, Convert.ToInt32(Resources.Resource.PROXY_PORT));
                if (Resources.Resource.PROXY_USER != "" && Resources.Resource.PROXY_PASSWORD != "")
                {
                    ws.Proxy.Credentials = new System.Net.NetworkCredential(Resources.Resource.PROXY_USER, Resources.Resource.PROXY_PASSWORD);
                }
            }

            if (Resources.Resource.PROD == "true")
            {
                ws.Url = Resources.Resource.ENDPOINT_WEB;
            }

            ws.Credentials = new System.Net.NetworkCredential(Resources.Resource.MERCHANT_ID, Resources.Resource.ACCESS_KEY);

            resultat = ws.doWebPayment(payment, Resources.Resource.RETURN_URL, Resources.Resource.CANCEL_URL, order,
                                       Resources.Resource.NOTIFICATION_URL, selectedCrontractList, privateDataList,
                                       Resources.Resource.LANGUAGE_CODE, Resources.Resource.CUSTOM_PAYMENT_PAGE_CODE, buyer,
                                       Resources.Resource.SECURITY_MODE, recurring, Resources.Resource.CUSTOM_PAYMENT_TEMPLATE_URL, out token, out redirectURL);

            debug = ((CheckBox)(Page.PreviousPage.FindControl("doWebPayment").FindControl("debug"))).Checked;
        }
        catch (Exception exc)
        {
            errorMessage = exc.Message;
            errorDetails = exc.ToString();
        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            WebPaymentAPI ws = new WebPaymentAPI();

            // PAYMENT
            payment.amount = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentAmount"))).Text;
            payment.mode   = ((DropDownList)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentMode"))).Text;
            payment.action = ((DropDownList)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentFonction"))).Text;

            payment.currency = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentCurrency"))).Text;
            if (payment.currency == "")
            {
                payment.currency = Resources.Resource.PAYMENT_CURRENCY;
            }

            payment.contractNumber = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentContractNumber"))).Text;
            contractNumberList     = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentContractNumberList"))).Text;

            if (contractNumberList.Contains(";"))
            {
                string[] split = contractNumberList.Split(new Char[] { ';' });
                selectedCrontractList = split;
            }
            else
            {
                selectedCrontractList.SetValue(contractNumberList, 0);
            }

            payment.differedActionDate = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("paymentDifferedActionDate"))).Text; // Format : "dd/mm/yy"


            // ORDER
            order.@ref    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderRef"))).Text;
            order.origin  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderOrigin"))).Text;
            order.country = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderCountry"))).Text;
            order.taxes   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderTaxes"))).Text;

            order.currency = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderCurrency"))).Text;
            if (order.currency == "")
            {
                order.currency = Resources.Resource.ORDER_CURRENCY;
            }

            order.amount = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderAmount"))).Text;
            order.date   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDate"))).Text; // format : "dd/mm/yyyy HH24:MM"

            // ORDER DETAILS
            orderDetail1.@ref     = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailRef1"))).Text;
            orderDetail1.price    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailPrice1"))).Text;
            orderDetail1.quantity = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailQuantity1"))).Text;
            orderDetail1.comment  = ((HtmlTextArea)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailComment1"))).Value;

            orderDetail2.@ref     = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailRef2"))).Text;
            orderDetail2.price    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailPrice2"))).Text;
            orderDetail2.quantity = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailQuantity2"))).Text;
            orderDetail2.comment  = ((HtmlTextArea)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("orderDetailComment2"))).Value;

            order.details = new orderDetail[2];
            order.details.SetValue(orderDetail1, 0);
            order.details.SetValue(orderDetail2, 1);

            // ADDRESS (optional)
            address.name     = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressName"))).Text;
            address.street1  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressStreet1"))).Text;
            address.street2  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressStreet2"))).Text;
            address.cityName = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressCity"))).Text;
            address.zipCode  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressZipCode"))).Text;
            address.country  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressCountry"))).Text;
            address.phone    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("addressPhone"))).Text;

            // BUYER (optional)
            buyer.shippingAdress       = address;
            buyer.walletId             = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerWalletId"))).Text;
            buyer.lastName             = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerLastName"))).Text;
            buyer.firstName            = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerFirstName"))).Text;
            buyer.email                = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerEmail"))).Text;
            buyer.accountCreateDate    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerAccountCreateDate"))).Text; // format : "dd/mm/yy"
            buyer.accountAverageAmount = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerAverageAmount"))).Text;
            buyer.accountOrderCount    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("buyerOrderCount"))).Text;

            // PRIVATE DATA (optional)
            privateData1.key   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataKey1"))).Text;
            privateData1.value = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataValue1"))).Text;
            privateData2.key   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataKey2"))).Text;
            privateData2.value = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataValue2"))).Text;
            privateData3.key   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataKey3"))).Text;
            privateData3.value = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("privateDataValue3"))).Text;

            privateDataList.SetValue(privateData1, 0);
            privateDataList.SetValue(privateData2, 1);
            privateDataList.SetValue(privateData3, 2);

            // TRANSACTION OPTIONS
            string notificationURL = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("notificationURL"))).Text;
            if (notificationURL == "")
            {
                notificationURL = Resources.Resource.NOTIFICATION_URL;
            }

            string returnURL = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("returnURL"))).Text;
            if (returnURL == "")
            {
                returnURL = Resources.Resource.RETURN_URL;
            }

            string cancelURL = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("cancelURL"))).Text;
            if (cancelURL == "")
            {
                cancelURL = Resources.Resource.CANCEL_URL;
            }

            string customPaymentPageCode = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("customPaymentPageCode"))).Text;
            if (customPaymentPageCode == "")
            {
                customPaymentPageCode = Resources.Resource.CUSTOM_PAYMENT_PAGE_CODE;
            }

            string customPaymentTemplateURL = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("customPaymentTemplateURL"))).Text;
            if (customPaymentTemplateURL == "")
            {
                customPaymentTemplateURL = Resources.Resource.CUSTOM_PAYMENT_TEMPLATE_URL;
            }

            string languageCode = ((DropDownList)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("languageCode"))).Text;
            if (languageCode == "")
            {
                languageCode = Resources.Resource.LANGUAGE_CODE;
            }

            // RECCURENT
            bool recurringCheck = ((CheckBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurring"))).Checked;
            if ((recurringCheck) || (payment.mode == "NX") || (payment.mode == "REC"))
            {
                recurring.firstAmount  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringFirstAmount"))).Text;
                recurring.billingLeft  = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringBillingLeft"))).Text;
                recurring.amount       = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringAmount"))).Text;
                recurring.billingCycle = ((DropDownList)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringBillingCycle"))).Text;
                recurring.startDate    = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringStartDate"))).Text;  // format : "dd/mm/yyyy"
                recurring.billingDay   = ((TextBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("recurringBillingDay"))).Text; // Format : "dd"
            }
            else
            {
                recurring = null;
            }

            //PROXY
            if (Resources.Resource.PROXY_HOST != "" && Resources.Resource.PROXY_PORT != "")
            {
                ws.Proxy = new System.Net.WebProxy(Resources.Resource.PROXY_HOST, Convert.ToInt32(Resources.Resource.PROXY_PORT));
                if (Resources.Resource.PROXY_USER != "" && Resources.Resource.PROXY_PASSWORD != "")
                {
                    ws.Proxy.Credentials = new System.Net.NetworkCredential(Resources.Resource.PROXY_USER, Resources.Resource.PROXY_PASSWORD);
                }
            }

            if (Resources.Resource.PROD == "true")
            {
                ws.Url = Resources.Resource.ENDPOINT_WEB;
            }

            ws.Credentials = new System.Net.NetworkCredential(Resources.Resource.MERCHANT_ID, Resources.Resource.ACCESS_KEY);

            resultat = ws.doWebPayment(payment, returnURL, cancelURL, order, notificationURL, selectedCrontractList, privateDataList, languageCode,
                                       customPaymentPageCode, buyer, Resources.Resource.SECURITY_MODE, recurring, customPaymentTemplateURL, out token, out redirectURL);

            debug = ((CheckBox)(Page.PreviousPage.FindControl("fullWebPayment").FindControl("debug"))).Checked;
        }
        catch (Exception exc)
        {
            errorMessage = exc.Message;
            errorDetails = exc.ToString();
        }
    }
    protected void ButtonDoPayment_Click(object sender, EventArgs e)
    {
        // Retrieve card informations
        card myCard = new card();

        myCard.number            = TextBoxCardNumber.Text;
        myCard.type              = DropDownListCardType.SelectedValue;
        myCard.expirationDate    = TextBoxCardExpiration.Text;
        myCard.cvx               = TextBoxCardCryptogram.Text;
        myCard.ownerBirthdayDate = TextBoxCardBirthday.Text;
        myCard.password          = TextBoxCardPassword.Text;

        // Retrieve payment informations
        payment myPayment = new payment();

        myPayment.amount             = TextBoxPaymentAmount.Text;
        myPayment.currency           = TextBoxPaymentCurrency.Text;
        myPayment.action             = DropDownListPaymentFunction.SelectedValue;
        myPayment.mode               = DropDownListPaymentMode.SelectedValue;;
        myPayment.contractNumber     = TextBoxPaymentContract.Text;
        myPayment.differedActionDate = TextBoxPaymentDifferedDate.Text;

        // Retrieve order informations
        order myOrder = new order();

        myOrder.@ref     = TextBoxOrderReference.Text;
        myOrder.origin   = TextBoxOrderOrigin.Text;
        myOrder.country  = TextBoxOrderCountry.Text;
        myOrder.taxes    = TextBoxOrderTaxes.Text;
        myOrder.currency = TextBoxOrderCurrency.Text;
        myOrder.amount   = TextBoxOrderAmount.Text;
        myOrder.date     = TextBoxOrderDate.Text;
        // Retrieve order details (first part)
        orderDetail myOrderDetails1 = new orderDetail();

        myOrderDetails1.@ref     = TextBoxItem1Reference.Text;
        myOrderDetails1.price    = TextBoxItem1Price.Text;
        myOrderDetails1.quantity = TextBoxItem1Quantity.Text;
        myOrderDetails1.comment  = TextBoxItem1Comment.Text;
        // Retrieve order details (second part)
        orderDetail myOrderDetails2 = new orderDetail();

        myOrderDetails2.@ref     = TextBoxItem2Reference.Text;
        myOrderDetails2.price    = TextBoxItem2Price.Text;
        myOrderDetails2.quantity = TextBoxItem2Quantity.Text;
        myOrderDetails2.comment  = TextBoxItem2Comment.Text;
        myOrder.details          = new orderDetail[] { myOrderDetails1, myOrderDetails2 };

        // Retrieve private datas
        privateData myPrivateData1 = new privateData();
        privateData myPrivateData2 = new privateData();
        privateData myPrivateData3 = new privateData();

        myPrivateData1.key   = TextBoxPrivateDataKey1.Text;
        myPrivateData1.value = TextBoxPrivateDataValue1.Text;
        myPrivateData2.key   = TextBoxPrivateDataKey2.Text;
        myPrivateData2.value = TextBoxPrivateDataValue2.Text;
        myPrivateData3.key   = TextBoxPrivateDataKey2.Text;
        myPrivateData3.value = TextBoxPrivateDataValue3.Text;
        var myPrivateDataList = new privateData[] { myPrivateData1, myPrivateData2, myPrivateData3 };

        // Retrieve buyer informations
        buyer myBuyer = new buyer();

        myBuyer.email                = TextBoxBuyerEmail.Text;
        myBuyer.accountCreateDate    = TextBoxBuyerAccountDate.Text;
        myBuyer.accountAverageAmount = TextBoxBuyerAverageAmount.Text;
        myBuyer.accountOrderCount    = TextBoxBuyerOrderCount.Text;

        //Returned datas
        transaction   myTransaction   = new transaction();
        authorization myAuthorization = new authorization();

        //Retrieve Web Service Version

        string transient           = null;
        string linkedTransactionId = null;

        //string contractNumber = myPayment.contractNumber;
        string contractNumber;

        string           resultContainer;
        extendedCardType extendedCard;
        cardOut          cardOut;
        recurring        recurring = null;

        try
        {
            var    client = PaymentApiFactory.GetDirectPaymentAPIClient();
            result Result = client.doAuthorization(ref transient, GlobalVariables.APIVersion, myPayment, null, myCard, myOrder, myBuyer, null, ref myPrivateDataList, null, null,
                                                   null, null, ref linkedTransactionId, recurring, out myTransaction, out myAuthorization, out cardOut, out extendedCard, out contractNumber, out resultContainer);

            //Returned datas
            TextBoxResultCode.Text         = Result.code;
            TextBoxResultShortMessage.Text = Result.shortMessage;
            TextBoxResultLongMessage.Text  = Result.longMessage;

            TextBoxTransactionID.Text = myTransaction.id;
        }
        catch (Exception E)
        {
            LabelError.Visible = true;
            LabelError.Text    = "Error : " + E.ToString();
        }
    }