1

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 ?

Cédric Boivin
  • 10,854
  • 13
  • 57
  • 98

1 Answers1

0

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;
Rolwin Crasta
  • 4,219
  • 3
  • 35
  • 45
  • Did you verify the url you are providing, if its the correct one – Rolwin Crasta Oct 08 '15 at 10:54
  • Also I do not see a SDK for .NET Available from wePay, i think you need to go with Custom checkout instead of Embedded Checkout – Rolwin Crasta Oct 08 '15 at 11:00
  • i know there no SDK, it's the reason why i try to implement my own handler. It's suppose to only ititiate the communication with the server and received a valid url to redirect the iframe – Cédric Boivin Oct 08 '15 at 11:08
  • The issue is with the Json, kindly replace accountID with account_id in the json, i have modified my answer above, Also my guess is you need to Authorize this request? OAuth2? – Rolwin Crasta Oct 08 '15 at 11:14
  • make some sens to Authenticate the request. I will try that – Cédric Boivin Oct 08 '15 at 11:23