找到你要的答案

Q:WePay embedCheckout with c#

Q:WePay embedCheckout与C #

Hello i try to create an embed payment in my web site with Wepay.

In PHP the code example is

<?php
    // WePay PHP SDK - http://git.io/mY7iQQ
    require 'wepay.php';

    // application settings
    $account_id = 123456789; // your app's account_id
    $client_id = 123456789;
    $client_secret = "1a3b5c7d9";
    $access_token = "STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20"; // your app's access_token

    // change to useProduction for live environments
    Wepay::useStaging($client_id, $client_secret);

    $wepay = new WePay($access_token);

    // create the checkout
    $response = $wepay->request('checkout/create', array(
        'account_id'        => $account_id,
        'amount'            => '24.95',
        'short_description' => 'Services rendered by freelancer',
        'type'              => 'service',
        'currency'          => 'USD'
    ));

    // display the response
    print_r($response);
?>

So i try to create my "own" handler to initiate the paiement. I create my ashx that will call the "/checkout/create" page but no success.

There is a sample of my code.

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Timeout = Timeout;
            objRequest.Method = "POST";
            objRequest.ContentType = "text/json";
            objRequest.ContentLength = strPost.Length;
string strPost = "{\"accountID\":\"528754\",\"client_id\":\"2544544\",\"client_secret\":\"0454a547\",\"access_token\":\"xxxxxx\",\"amount\":\"5\",\"short_description\":\"messages\",\"type\":\"service\",\"currency\":\"CAD\",\"redirect_uri\":\"https://www.mywebsite.com/sucess.aspx\"}"
            try
            {
                using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost);
                    myWriter.Flush();
                    myWriter.Close();
                }
            }
            catch (Exception e)
            {
            }


            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            string result;
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
            }


            return result;

I always received a bad request .... any idea ?

你好,我想在我的网站,我们创建一个嵌入的支付。

在PHP的代码示例

<?php
    // WePay PHP SDK - http://git.io/mY7iQQ
    require 'wepay.php';

    // application settings
    $account_id = 123456789; // your app's account_id
    $client_id = 123456789;
    $client_secret = "1a3b5c7d9";
    $access_token = "STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20"; // your app's access_token

    // change to useProduction for live environments
    Wepay::useStaging($client_id, $client_secret);

    $wepay = new WePay($access_token);

    // create the checkout
    $response = $wepay->request('checkout/create', array(
        'account_id'        => $account_id,
        'amount'            => '24.95',
        'short_description' => 'Services rendered by freelancer',
        'type'              => 'service',
        'currency'          => 'USD'
    ));

    // display the response
    print_r($response);
?>

所以我要创造我的“自己”的处理程序来启动paiement。我创造我的处理,将其称为“/结帐/创建”页面,但没有成功。

有我的代码示例。

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Timeout = Timeout;
            objRequest.Method = "POST";
            objRequest.ContentType = "text/json";
            objRequest.ContentLength = strPost.Length;
string strPost = "{\"accountID\":\"528754\",\"client_id\":\"2544544\",\"client_secret\":\"0454a547\",\"access_token\":\"xxxxxx\",\"amount\":\"5\",\"short_description\":\"messages\",\"type\":\"service\",\"currency\":\"CAD\",\"redirect_uri\":\"https://www.mywebsite.com/sucess.aspx\"}"
            try
            {
                using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost);
                    myWriter.Flush();
                    myWriter.Close();
                }
            }
            catch (Exception e)
            {
            }


            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            string result;
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
            }


            return result;

我总是收到一个坏要求…有什么想法吗?

answer1: 回答1:

Try changing the contetType to

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Timeout = Timeout;
            objRequest.Method = "POST";
           objRequest.ContentType = "application/json";
            objRequest.ContentLength = strPost.Length;
string strPost = "{\"account_id\":\"528754\",\"client_id\":\"2544544\",\"client_secret\":\"0454a547\",\"access_token\":\"xxxxxx\",\"amount\":\"5\",\"short_description\":\"messages\",\"type\":\"service\",\"currency\":\"CAD\",\"redirect_uri\":\"https://www.mywebsite.com/sucess.aspx\"}"
            try
            {
                using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost);
                    myWriter.Flush();
                    myWriter.Close();
                }
            }
            catch (Exception e)
            {
            }


            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            string result;
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
            }


            return result;

尝试改变contettype来

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Timeout = Timeout;
            objRequest.Method = "POST";
           objRequest.ContentType = "application/json";
            objRequest.ContentLength = strPost.Length;
string strPost = "{\"account_id\":\"528754\",\"client_id\":\"2544544\",\"client_secret\":\"0454a547\",\"access_token\":\"xxxxxx\",\"amount\":\"5\",\"short_description\":\"messages\",\"type\":\"service\",\"currency\":\"CAD\",\"redirect_uri\":\"https://www.mywebsite.com/sucess.aspx\"}"
            try
            {
                using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost);
                    myWriter.Flush();
                    myWriter.Close();
                }
            }
            catch (Exception e)
            {
            }


            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            string result;
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
            }


            return result;
c#  web  wepay