WePay嵌入式checkout与c#

本文关键字:checkout 嵌入式 WePay | 更新日期: 2023-09-27 18:16:33

您好,我尝试在我的网站上创建一个嵌入支付与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);
?>

所以我尝试创建我自己的处理程序来启动支付。我创建了我的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;

我总是收到一个错误的请求....你知道吗?

WePay嵌入式checkout与c#

尝试将contttype更改为

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;