WePay使用c#embedCheckout

时间:2015-10-08 10:31:54

标签: c# web wepay

您好我尝试使用Wepay在我的网站上创建嵌入付款。

在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。我创建了我的ashx,它将调用“/ checkout / create”页面,但没有成功。

我的代码有一个示例。

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;

我总是收到一个糟糕的请求....任何想法?

1 个答案:

答案 0 :(得分:0)

尝试将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;