Apple In app purchase verify recurring payment in .NET Java 21002 exception - iphone

We are trying to verify a receipt for a RECURRING in-app payment made in iOS.
Referring to an earlier question on stack (http://stackoverflow.com/questions/11085847/keep-getting-21002-java-lang-nullpointerexception-on-apples-verifyreceipt), I manage to use the following code which sends in a JSON object made up of our receipt and sharedSecret key but we get the dreaded {"status":21002, "exception":"java.lang.NullPointerException"} error
Dim json As String ="{'receipt-data':'base64encoded receipt data','password':'YYYY'}"
Dim webRequest = System.Net.HttpWebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt")
webRequest.ContentType = "text/plain"
webRequest.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(json)
webRequest.ContentLength = byteArray.Length
Using stream = webRequest.GetRequestStream()
stream.Write(byteArray, 0, byteArray.Length)
stream.Flush()
End Using
Dim resp = webRequest.GetResponse()
If resp IsNot Nothing Then
Using sr = New System.IO.StreamReader(resp.GetResponseStream())
Dim result = sr.ReadToEnd().Trim()
' always getting '21002' 'java.lang.NullPointerException'
Response.Write(result.ToString())
End Using
End If
Any help appreciated!

Related

Docusign Soap API returns Unspecified Error

I have been trying to send a docusign envelope from Salesforce using the docusign SOAP API. I am using the CreateEnvelopeFromTemplates method of the Docusign API, I have a functional template created in my docusign sandbox, but everytime I send the request I get an Unspecified Error in my response. Below is the code the I am using
wwwDocusignNetApi30.EnvelopeInformation envelope = new wwwDocusignNetApi30.EnvelopeInformation();
envelope.Subject = 'Envelope Subject' ;
envelope.EmailBlurb = 'Email Blurb';
envelope.AccountId = '********-****-****-****-************';
//use custom field to store the id of the record that initiated the transaction
envelope.CustomFields = new wwwDocusignNetApi30.ArrayOfCustomField();
envelope.CustomFields.CustomField = new wwwDocusignNetApi30.CustomField[2];
wwwDocusignNetApi30.CustomField myCustomField = new wwwDocusignNetApi30.CustomField();
myCustomField.Name = 'DSFSSourceObjectId';
myCustomField.Value = '0012600000PQn9g';
myCustomField.Show = 'false';
myCustomField.Required = 'false';
myCustomField.CustomFieldType = 'Text';
envelope.CustomFields.CustomField.add(myCustomField);
wwwDocusignNetApi30.ArrayOfTemplateReference templateArray = new wwwDocusignNetApi30.ArrayOfTemplateReference();
templateArray.TemplateReference = new wwwDocusignNetApi30.TemplateReference[2];
wwwDocusignNetApi30.TemplateReference templat = new wwwDocusignNetApi30.TemplateReference();// TemplateReferences
templat.Template = '********-****-****-****-************';
templat.TemplateLocation = 'Server';
wwwDocusignNetApi30.ArrayOfRecipient1 recArray = new wwwDocusignNetApi30.ArrayOfRecipient1();
recArray.Recipient = new wwwDocusignNetApi30.Recipient[2];
wwwDocusignNetApi30.Recipient recipient = new wwwDocusignNetApi30.Recipient();
recipient.ID = 100987;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 2;
recipient.Email = 'example#example.com';
recipient.UserName = 'Test';
recArray.Recipient.add(recipient);
wwwDocusignNetApi30.TemplateReferenceRoleAssignment trra = new wwwDocusignNetApi30.TemplateReferenceRoleAssignment();
trra.RoleName='Signer 1';
trra.RecipientID = recipient.ID;
wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment roleArray = new wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment();
roleArray.RoleAssignment = new wwwDocusignNetApi30.TemplateReferenceRoleAssignment[1];
roleArray.RoleAssignment.add(trra);
templat.RoleAssignments = new wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment();
templat.RoleAssignments = (roleArray);
templateArray.TemplateReference.add(templat);
String auth = '<DocuSignCredentials><Username>********-****-****-****-************</Username><Password>PASSWORD</Password><IntegratorKey>********-****-****-****-************</IntegratorKey></DocuSignCredentials>';
wwwDocusignNetApi30.APIServiceSoap service = new wwwDocusignNetApi30.APIServiceSoap();
service.inputHttpHeaders_x = new Map<String, String>();
service.inputHttpHeaders_x.put('X-DocuSign-Authentication',auth);
service.CreateEnvelopeFromTemplates(templateArray,recArray,envelope,true);
Below is the response I receive:
System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Unspecified_Error faultcode=soap:Server faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx
Since the error message is vague, I am not able to debug the issue. Any help is appreciated.
I suggest that you start with a simpler request. Look at the recipes on github.com/docusign that start with sfdc
Get the simpler request working, then add features to get it to your needs.
One thing I did notice was that you are not giving a routing order of 1 to your only recipient. But that's probably OK.
I'm not sure that your template reference is correct since you should not be using composite templates for a simple template reference. Unfortunately I don't have a lot of experience with the soap api. HTH.

Google API v3 .Net client Unauthorized client or scope in request

I'm getting the error message "Unauthorized client or scope in request." When the following code executes. If I remove the .User = myUserEmail parameter I get a "Insufficient Permission [403]" error message. If I had to guess, I would guess that the issue is the .user parameter I'm using. But, I don't what I'm doing wrong there. I'm using the email address associated with the Google Account I normally use to login to Google Analytics.
Private myClientEmail As String = System.Configuration.ConfigurationManager.AppSettings("clientEmail").ToString()
Private myP12Path As String = System.Configuration.ConfigurationManager.AppSettings("p12Path").ToString()
Private myP12Password As String = System.Configuration.ConfigurationManager.AppSettings("p12Password").ToString()
Private myUserEmail As String = System.Configuration.ConfigurationManager.AppSettings("userEmail").ToString()
Private myApplicationName As String = System.Configuration.ConfigurationManager.AppSettings("applicationName").ToString()
Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add("https://www.googleapis.com/auth/drive.readonly")
Dim certificate As X509Certificate2 = New X509Certificate2(myP12Path, myP12Password, X509KeyStorageFlags.Exportable)
Dim credential As ServiceAccountCredential = New ServiceAccountCredential(New ServiceAccountCredential.Initializer(myClientEmail) With {
.Scopes = scopes,
.User = myUserEmail
}.FromCertificate(certificate))
Dim service As AnalyticsService = New AnalyticsService(New BaseClientService.Initializer() With {
.HttpClientInitializer = credential,
.ApplicationName = myApplicationName
})
Dim profileId As String = "ga:12345678"
Dim startDate As String = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd")
Dim endDate As String = DateTime.Today.ToString("yyyy-MM-dd")
Dim metrics As String = "ga:visits"
Dim request As DataResource.GaResource.GetRequest = service.Data.Ga.Get(profileId, startDate, endDate, metrics)
request.Dimensions = "ga:date"
Dim data As GaData = request.Execute()
I found the error in my ways...
Somewhere along the lines I inadvertently changed the scope to the "drive.readonly". When I'm trying to work with the "analytics.readonly".

Facebook API: error 400 when posting with test user, but works with administrator

I have facebook integrated on my login page, and now I'm trying to call a build-in action: books.rates using a Test App.
My app gets a valid access_token, and creates new feed items without problems. But when I'm tryng to make a books.rates API call, only works if the logged user is a real person (in my tests is me, also the App administrator), and fails allways with Error 400 when I try to rate a book with a Test User.
In both cases, the code is the same (only access_token and userid changes) and has "publish_actions" premission enabled. I think I'm missing something on Test App configuration, but I'm really lost right now.
Thanks!
Update 1
This is the code that makes the action. It's a test code so its very basic
Dictionary<string, string> postInfo = new Dictionary<string, string>();
postInfo["book"] = "http://www.whakoom.com/comics/6jMl7/52/4";
postInfo["rating:value"] = "4";
postInfo["rating:scale"] = "5";
postInfo["fb:explicitly_shared"] = "true";
string graphUrl = string.Format("https://graph.facebook.com/v2.1/{0}/books.rates?access_token={1}", FbUserID, FbAccessToken);
string fbResp = PostPageContent(graphUrl, postInfo);
private static string PostPageContent(string url, Dictionary<string,string> postData)
{
string postInfo = string.Empty;
foreach(string key in postData.Keys)
{
if (postInfo.Length > 0)
postInfo += "&";
postInfo += string.Format("{0}={1}", HttpContext.Current.Server.UrlEncode(key), HttpContext.Current.Server.UrlEncode(postData[key]));
}
var request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postInfo.Length;
StreamWriter streamOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(postInfo);
streamOut.Close();
string retValue = string.Empty;
WebResponse response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
retValue = reader.ReadToEnd();
reader.Close();
return retValue;
It seems that Test App with Test Users is unable to make books.rates calls until the main App is approved. The same api calls targeting a real App with a Test User works without problems.

having Issues connecting to quickbooks online via IPP and .net devkit

I am trying to connect to QB online and I am having issues. I have created a demo account for QBO and added my test app to the account and granted access for my app. I have my consumer key and secret tokens. I have installed the .net devkit and have my test project setup.
I am using the code example from here...
https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0200_DevKits_for_Intuit_Partner_Platform/0100_IPP_.NET_DevKit/0299_Synchronous_Calls/0001_Data_Service_APIs
everything works until I call the add method to create a customer. the same goes for anything else I try to do as far as adding data.
This is the error I get...
"message=Exception authenticating OAuth; errorCode=003200; statusCode=401; source=OAuthStrategy; oauth_problem=token_rejected; cause=net.oauth.OAuthProblemException: token_rejected"
It says token rejected so I am unclear as to what I am missing. These are the tokens given to me in the online app section.
here is my code..
Dim AccessToken As String = [redacted]
Dim AccessTokenSecret As String = [redacted]
Dim ConsumerKey As String = [redacted]
Dim ConsumerSecret As String = [redacted]
Dim OAuthValidator As OAuthRequestValidator = New OAuthRequestValidator(AccessToken, AccessTokenSecret, ConsumerKey, ConsumerSecret)
Dim Context As ServiceContext = New ServiceContext(OAuthValidator, RealmID, IntuitServicesType.QBD)
Dim dataServices As DataServices = New DataServices(Context)
Dim qbdCustomer As Customer = New Customer()
With qbdCustomer
qbdCustomer.Name = "My New Customer"
qbdCustomer.GivenName = "New Customer"
qbdCustomer.FamilyName = "New Customer"
End With
Dim customerAdded As Customer = dataServices.Add(qbdCustomer)
If you are trying to connect to QBO, you are using the wrong entities.
You should be using QBO and NOT QBD.
Also, your InitializeServiceContext looks like it is missing some parameters.

Strange Status Code From Apple Receipt Verification Sandbox

I make a post request of base64 encoded data to the receipt verification address as follows (this is in C#):
var postSerializer = new JavaScriptSerializer();
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(Receipt);
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
var temp = new Dictionary<string, string>();
temp.Add("receipt-data", returnValue);
string jsonReceipt = postSerializer.Serialize(temp);
request.Method = "POST";
request.ContentType = "application/json";
byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(jsonReceipt);
request.ContentLength = postBytes.Length;
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(postBytes, 0, postBytes.Length);
// Close the Stream object.
dataStream.Close();
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
I'm pretty sure things are in the right format because I'm not getting any exceptions back
from the apple receipt verification endpoint. The entirety of the response I get back is
{status : -42352}
And I can't find out what this error means anywhere. Does anyone know what this means or if there's an error in my code?
Just solved the same problem. Got the solution from here: Verify receipt for in App purchase
The problem was in post encoding. When I encoded post on my server using
$receipt = json_encode(array("receipt-data" => base64_encode($receiptdata)));
I had the same -42352 status. When I used my own function for encoding on iPhone - everything worked! Magic...