Paypal with express checkout to get BillingAgreementID - asp.net

I am working with the paypal using express checkout to get a billing agreement id.
I was following this guide:
https://www.x.com/developers/paypal/documentation-tools/how-authorize-and-run-reference-transaction-express-checkout
In the first step when i do "SetExpressCheckout":
The following is the code
public string SetExpressCheckout(string Amount)
{
string returnURL = "http://localhost:50325/ReviewOrder.aspx" + "?amount=" + Amount + "&PAYMENTREQUEST_0_CURRENCYCODE=USD";
string cancelURL = returnURL.Replace("ReviewOrder", "ExpCheckOut");
string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;
string strNVP = strCredentials;
strNVP += "&PAYMENTREQUEST_0_PAYMENTACTION=AUTHORIZATION&&PAYMENTREQUEST_0_AMT=25" + "&L_BILLINGTYPE0=MerchantInitiatedBilling" + "&RETURNURL=" + returnURL;
strNVP += "&CANCELURL=" + cancelURL;
strNVP += "&METHOD=SetExpressCheckout&VERSION=" + strAPIVersion + "&DESC=test EC payment" +"&NOSHIPPING=0" ;
//Create web request and web response objects, make sure you using the correct server (sandbox/live)
HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
//Set WebRequest Properties
wrWebRequest.Method = "POST";
// write the form values into the request message
StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
requestWriter.Write(strNVP);
requestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());
// and read the response
string responseData = responseReader.ReadToEnd();
responseReader.Close();
return responseData;
}
The response is:
TOKEN=EC-09082530FY878870B&
TIMESTAMP=2013-03-25T00:45:56Z&
CORRELATIONID=3d33037174d55&
ACK=SuccessWithWarning&
VERSION=86&
BUILD=5479129&
L_ERRORCODE0=11452&
L_SHORTMESSAGE0=Merchant not enabled for reference transactions&
L_LONGMESSAGE0=Merchant not enabled for reference transactions&
L_SEVERITYCODE0=Warning
How to to get a BillingAgreeentd in Step 3:
Code for step 3 is:
public string GetBillingAgreementID()
{
string returnURL = "http://localhost:50325/ReviewOrder.aspx" + "?amount=" + Amount + "¤cy=USD";
string cancelURL = returnURL.Replace("ReviewOrder", "ExpCheckOut");
string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;
string strNVP = strCredentials;
strNVP += "&RETURNURL=" + returnURL;
strNVP += "&CANCELURL=" + cancelURL;
strNVP += "&METHOD=CreateBillingAgreement&VERSION=" + strAPIVersion + "&TOKEN=" + Session["Token"];
//Create web request and web response objects, make sure you using the correct server (sandbox/live)
HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
//Set WebRequest Properties
wrWebRequest.Method = "POST";
// write the form values into the request message
StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
requestWriter.Write(strNVP);
requestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());
// and read the response
string responseData = responseReader.ReadToEnd();
responseReader.Close();
return responseData;
}
Response is:
TIMESTAMP=2013-03-25T00:51:34Z&
CORRELATIONID=854e6beed1e82&
ACK=Failure&
VERSION=86&
BUILD=5479129&
L_ERRORCODE0=11455&
L_SHORTMESSAGE0=Buyer did not accept billing agreement&
L_LONGMESSAGE0=Buyer did not accept billing agreement&
L_SEVERITYCODE0=Error
How to get a BillingAgreemntId?
Is that because of "L_SHORTMESSAGE0=Merchant not enabled for reference transactions" this message from "SetExpressCheckout" am i not able to get BillingAgreementID?
Please help me on this. Thanks.

You would need to contact PayPal and request this to be enabled on the account, if this is for a live account. If you are needing it enabled on the sandbox, you would need to contact PayPal MTS and have this enabled on your sandbox account.

Related

SMS application is not sending special characters asp.net mvc

I have an ASP.NET MVC application that sends SMS from the web, problem is it doesn't send some special characters such as ~!##$&, when I send something like &&&&, it doesn't send SMS, if I send something like dan&dan it will send the first dan and remove remaining character and word.
Hare is my code:
public ActionResult SendSms(SendBatch member)
{
StreamReader objReader;
WebClient client = new WebClient();
string mess = member.Message;
string cell = member.Cell;
string pass = "mypassword";
string user = "username";
string baseurl = "http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0?" + "username=" + user + "&" + "password=" + pass + "&" + "message=" + mess + "&" + "msisdn=" + cell;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(baseurl);
try
{
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
objReader = new StreamReader(objStream);
objReader.Close();
}
catch (Exception ex)
{
ex.ToString();
}
}
Hope someone can assist.
Because you use Get method to call SMS web service, illegal characters automatically removed from your SMS. You need to use HttpUtility.UrlEncode to encode characters before sending.
Thanks so much for the light, i manage to find a solution using HttpUtility.UrlEncode:
public ActionResult SendSms(SendBatch member)
{
StreamReader objReader;
WebClient client = new WebClient();
string mess = member.Message;
string cell = member.Cell;
string pass = "mypassword";
string user = "username";
string message = HttpUtility.UrlEncode(mess, System.Text.Encoding.GetEncoding("ISO-8859-1"));
string baseurl = "http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0?" + "username=" + user + "&" + "password=" + pass + "&" + "message=" + message + "&" + "msisdn=" + cell;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(baseurl);
try
{
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
objReader = new StreamReader(objStream);
objReader.Close();
}
catch (Exception ex)
{
ex.ToString();
}
}

I get an error when i make post request on Twilio sending sms api in Asp.net

I am learning Twilio Sending SMS tool. I created a trial account and have a verified phone number too.
I made post request to send sms through my aspx page but I got an authentication error.
Here is the code. Could anyone tell me what the problem is?
string url ="https://api.twilio.com/2010-04-01/Accounts/"+accontSid+ ":" + authenticationToken +"/SMS/Messages.json";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
var authInfo = accSid + ":" + authToken;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Method = "POST";
var postData = "{\"To\":" +"\"" + ToNumber + "\"" + ", \"From\":" + "\"" + FromNumber + "\"" + ", \"Body\":" + "\"" + Body + "\"}";
var data = Encoding.UTF8.GetBytes(postData);
//request.ContentType = "application/json; charset=utf-8";
request.ContentType = "application/json";
request.ContentLength = data.Length;
Stream writer = null;
writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close();
request.Headers["Authorization"] = "Basic"+authInfo;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();
When I run this code, I get this error:
{"code": 20003, "detail": "Your AccountSid or AuthToken was incorrect.", "message": "Authentication Error - No credentials provided", "more_info": "https://www.twilio.com/docs/errors/20003", "status": 401}
What changes I should make?
Edit Change
try
{
string url ="https://api.twilio.com/2010-04-01/Accounts/"+accountSid+"/SMS/Messages.json";
string FromNumber = "+12012317746";
string ToNumber = "+91xxxxxxxxxx";
string Body = "Hello This is my test account.";
TwilioRestClient client = new TwilioRestClient(accSid, authToken);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
var authInfo = accSid + ":" + authToken;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Method = "POST";
var postData = "{\"To\":" +"\"" + ToNumber + "\"" + ", \"From\":" + "\"" + FromNumber + "\"" + ", \"Body\":" + "\"" + Body + "\"}";
var data = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream writer = null;
writer = request.GetRequestStream();
writer.Write(data, 0, data.Length);
writer.Close();
request.Headers["Authorization"] = "Basic "+authInfo;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();
client.SendMessage("+12012317746 ", txtToNo.Text, txtMsg.Text);
}
catch (WebException ex)
{
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
Response.Write(reader.ReadToEnd());
}
}
I still get the same error.
Twilio developer evangelist here.
There is a couple of issues here. As CodeCaster pointed out, you do not need the Auth Token as part of the URL, just the Account SID.
Your Authorization header looks as though it is set up incorrectly, you don't have a space between "Basic" and the authInfo.
You have also set up the request type as "application/json". Twilio expects your POST request to have form encoded data as the body and the content type "application/x-www-form-urlencoded".
Twilio actually supply a C# helper library that you can use to make sending messages in Asp.net easier. You don't need to worry about the basic setup of the HTTP request and can just get on with building your application.
There are quite a few problems with this code. The error itself is already pretty clear; this request provides a response which you should read:
detail: Your AccountSid or AuthToken was incorrect.
message: Authentication Error - No credentials provided
more_info: https://www.twilio.com/docs/errors/20003
Read the errors, visit the mentioned "more info" page and read the documentation. The problems with your code:
You only have to provide the Account ID in the request URI, so lose the + ":" + authenticationToken.
You're not properly writing the basic authentication header. You're missing a space between "Basic" and the base64-encoded credentials.
Borrowed from the just-posted other answer: the content-type of the request also is incorrect.
As explained in the "more info" and documentation links above, use a client library. You don't want to reinvent the wheel.
Especially if you look at the last point, all of this code could be replaced with the following:
string AccountSid = "AC5ef872f6da5a21de157d80997a64bd33";
string AuthToken = "[AuthToken]";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(
"+14158141829", "+16518675309",
"Hey Jenny! Good luck on the bar exam!", ...);

File created insted of Folder in Alfresco

I am trying to create a folder in Alfresco using XMSI below is the code i am using .
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
String host = "127.0.0.1";
int port = 9080;
String username = "admin";
String password = "admin";
String parentFolder = "Company%20Home";
String folderName = "sales3";
String description = "sales space3";
RulesRequest request = new RulesRequest();
//request.setRemediationProfileObj(remediationProfile);
Gson gs = new Gson();
String json = gs.toJson(request);
DefaultHttpClient client = new DefaultHttpClient();
RestClient rstClnt = new RestClient();
String ticket = rstClnt.restClientPost(json, "http://127.0.0.10:9080/alfresco/service/api/login?u=admin&pw=admin", client);
//String url = "http://" + host + ":" + port + "/alfresco/service/api/path/workspace/SpacesStore/" + parentFolder + "/children";
String url = "http://localhost:9080/alfresco/service/cmis/s/workspace:SpacesStore/i/078b05c6-14bd-439c-a1ae-db032c5d98fc/children?alf_ticket="+ticket;
String contentType = "application/atom+xml;type=entry";
String xml =
"<?xml version='1.0' encoding='utf-8'?>\n" +
"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>\n" +
"<title>" + folderName + "</title>\n" +
"<summary>" + description + "</summary>\n" +
"<cmis:object>\n"+
"<cmis:properties>\n" +
"<cmis:propertyString cmis:name='cmis:objectTypeId'>\n" +
"<cmis:value>cmis:folder</cmis:value>\n" +
"</cmis:propertyString>\n" +
"</cmis:properties>\n" +
"</cmis:object>\n" +
"</entry>\n";
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(host, port),
new UsernamePasswordCredentials(username, password));
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", contentType);
StringEntity requestEntity = new StringEntity(xml, "UTF-8");
httppost.setEntity(requestEntity);
System.out.println("executing request" + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content type: " + entity.getContentType());
long contentLength = entity.getContentLength();
System.out.println("Response content length: "
+ entity.getContentLength());
if (contentLength > 0) {
byte [] b = new byte[(int) contentLength];
entity.getContent().read(b);
System.out.println("Response content: " + new String(b));
}
entity.writeTo(System.out);
}
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
long end = System.currentTimeMillis();
System.out.println("Time spend: " + (end-start) + "ms");
}
Instead of creating a folder it is creating a file of size 0.
Thanks
Garvit
Your property is of the wrong type. You are incorrectly using cmis:propertyString instead of cmis:propertyId Try the following
<cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
<cmis:value>cmis:folder</cmis:value>
</cmis:propertyId>
As #Gagravarr says, problems like this are easily avoided if you can use well-known client libraries. If you are constructing the HTTP requests yourself you'd better have a good reason for that.

Paypal IPN integration issues

I am trying to process the response from paypal on my page. I found this code from paypal documentation itself. When the response is valid, some parameters needs to be processed like txn_id and payment_completed. How should i do that??
the code is as follows
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
// string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
if (strResponse == "VERIFIED")
{
//UPDATE YOUR DATABASE
//TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
//txWriter.WriteLine(strResponse);
//txWriter.Close();
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//UPDATE YOUR DATABASE
//TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
//txWriter.WriteLine(strResponse);
////log for manual investigation
//txWriter.Close();
}
else
{ //UPDATE YOUR DATABASE
//TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
//txWriter.WriteLine("Invalid");
////log response/ipn data for manual investigation
//txWriter.Close();
}
}
Give me some inputs please. Thanks
After you get the response and you know that is valid, the parameters have been posted to you and you can get them using the .Form For example:
if (strResponse == "VERIFIED")
{
// Now All informations are on
HttpContext.Current.Request.Form;
// for example you get the invoice like this
HttpContext.Current.Request.Form["invoice"]
// or the payment_status like
HttpContext.Current.Request.Form["payment_status"]
}
else
{
//log for manual investigation
}

remot server 403 error

hello i am working on asp.net and in that i want to add my contact list to constant contact website for that i have created trial account on constant contact. i used following code to add record to the constant contact database. but it show me following error
The remote server returned an error: (403) Forbidden.
i got exception on response part
Uri address=new Uri(sUri);
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Credentials=new NetworkCredential ((sAPIKey + "%" + sUsername), sPassword);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//Build data string
var data=new StringBuilder();
data.Append("activityType=" + HttpUtility.UrlEncode("ADD_CONTACTS", Encoding.UTF8));
data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name" + Convert.ToChar(10)), Encoding.UTF8));
data.Append(HttpUtility.UrlEncode((email.Text + ",HTML," + txtfname.Text + "," + txtlname.Text), Encoding.UTF8));
data.Append("&lists=" + HttpUtility.UrlEncode(sListUri));
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
string st = string.Empty;
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader reader = new StreamReader(response.GetResponseStream());
st = reader.ReadToEnd();
}
string sCode =Convert.ToString( Response.StatusCode);
thank you in advance.
If you open the page in firefox and inspect the response in firebug you will see the second part of the error number. 403 is just the first part. It might be 403.1 or 403.9 or whatever. there are lots and the specific one will help you narrow down the cause. Also, try the same in HTTPWatch.

Resources