Why does Stripe.com return error (402) Payment Required? - vb.net

I'm not seeing this particular error described in stripes API anywhere. Anyone know what's going on?
Here is my VB.net code to create a customer:
Function CreateStripeCustomer(ByVal Token As String) As String
'' The Stripe Account API Token - change this for testing
Dim STR_Stripe_API_Token As String = "sk_test_SECRET_TEST_KEY" '<-- test secret key. Change to live later.
''The Stripe API URL
Dim STR_Stripe_API_URL As String = "https://api.stripe.com/v1/customers"
''Creates a Web Client
Dim OBJ_Webclient As New System.Net.WebClient()
''Creates Credentials
Dim OBJ_Credentials As New System.Net.NetworkCredential(STR_Stripe_API_Token, "MY_STRIPE.COM_PASSWORD")
''Sets the Credentials on the Web Client
OBJ_Webclient.Credentials = OBJ_Credentials
''Creates a Transaction with Data that Will be Sent to Stripe
Dim OBJ_Transaction As New System.Collections.Specialized.NameValueCollection()
OBJ_Transaction.Add("email", "PERFECTLY_VALID_EMAIL")
OBJ_Transaction.Add("card", "PERFECTLY VALID TOKEN RETURNED BY STRIPE.JS")
''The Stripe Response String
Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))
Return STR_Response
End Function
The 402 "payment required" error is happening on the line:
Dim STR_Response As String = Encoding.ASCII.GetString(OBJ_Webclient.UploadValues(STR_Stripe_API_URL, OBJ_Transaction))

If you're seeing this in live, it's also possible the card number is simply incorrect, eg: if you inspect the body of the 402 response:

Well, I switched to my "LIVE" keys instead of my "TEST" keys, and that fixed it. Just wasted 3 hours of my life trying to fix this. Hope this helps somebody else.

The more correct answer is that you need to use the appropriate test card numbers. See https://stripe.com/docs/testing

Stripe provides a test environment in which you use the test publishable/secret keys, as oppose to waiting till production. However, what seems like the down side, which is in fact very helpful is that you need to comply to Stripe's testing conditions and use their given card numbers and inputs to test different aspects of your api call.
For example, in order to receive certain errors you can input these numbers:
card_declined: Use this special card number - 4000000000000002.
incorrect_number: Use a number that fails the Luhn check, e.g. 4242424242424241.
invalid_expiry_month: Use an invalid month e.g. 13.
invalid_expiry_year: Use a year in the past e.g. 1970.
invalid_cvc: Use a two digit number e.g. 99.
For more information refer to the link that Samir posted.

For iOS
If you are following tutorial from Ray Wunderlich website the reason why error may appear is that you run your test back end (web.rb file) and after that add you TEST_SECRET_KEY.
Go to the terminal click control+C, make sure you have already added your TEST_SECRET_KEY, save file and do ruby web.rb.
For now, everything should work fine.
For reference, I used this number of the card for testing: 4242 4242 4242 4242

Related

Unable to POST NZ employee openingBalances to Xero?

I am attempting to create a single opening balances record against an existing employee but keep getting a 400 Bad Request response with this detail...
At least one NZ opening balance item is required in the request
I am following the instructions as per this documentation...
https://developer.xero.com/documentation/api/payrollnz/employeeopeningbalances#post-opening-balances
URL : {DestinationID} is properly replaced with the employee GUIDhttps://api.xero.com/payroll.xro/2.0/employees/{DestinationID}/openingBalances
JSON Body[{"periodEndDate":"2011-01-30T00:00:00","daysPaid":5.00,"unpaidWeeks":0.00,"grossEarnings":1442.31}]
The Xero forums and support is pretty unreliable so I'm posting here in the hopes for a better response.
After some trial and error using the API Explorer that Xero provides I was able to get it working using their example....
I eventually learned that daysPaid and unpaidWeeks must both be integer whole numbers or else it fails.... The error message provided is misleading but this resolves the problem.

MS Access API Request

This is my first post here though have been using the great advice/solutions here for years so am very grateful. But this one, I can't find solution for.
I have an MS access front end/back end in use for various office admin tasks and records. Much of the data my office works with on a daily basis is cloud based. However API access is provided with app key and secret key. I have no issues using the API explorer with these keys, but can't get anything through code (VBA). I keep reading it is perfectly possible to do this with VBA which is why I kept trying different solutions, but now need help. (I have replaced URL and keys etc)
Dim myObj As New MSXML2.XMLHTTP60
Dim url, endPoint, params, tickers, appKey, secretKey As String
url = "theURL.com"
endPoint = "theEndPoint"
params = "id="
tickers = "1"
appKey = "12345678"
secretKey = "12345678"
myObj.Open "GET", url, False
myObj.setRequestHeader "Content-Type", "application/json"
myObj.setRequestHeader "app-key", appKey
myObj.setRequestHeader "secret-key", secretKey
myObj.send
This returns "App Key is required." I have tried various solutions including converting keys to Base64, putting the keys within the Open request, sending the keys as part of the send request etc. Always get "App Key is required" when reading response. I know in this code I have't actually requested anything but that returns same message when I do. I just wanted to keep what I posted simple.
Any help at all is greatly appreciated as this would allow great deal of automation for our office.
Thanks
James

I am trying to use Yodlee/executeUserSearchRequest as a RESTful request and need an answer on how to call

I am working with the Yodlee services in c# and using the RESTful api. So far I have successfully connected and logged in with my CobrandSession and UserSessionToken in the development environment. I used the sample apps provided in c# and with some advice from shreyans i got an app working. What I got working was
1) Get YodleeAuthentication
2) Get UserAuthentication
3) Get ItemSummaries
I am now trying to get the full transaction details for each of the Items (i.e. collections of accounts that are an Item)
reading the Docs here https://developer.yodlee.com/Indy_FinApp/Aggregation_Services_Guide/REST_API_Reference/executeUserSearchRequest it states that I need to call executeUserSearchRequest and then paginate through the results using the getUserTransactions. So I am stuck at this point. I dont really want a search which has parameters I just want ALL transactions for this account that I can see.
However, I am using the variables as defined in that page :-
var request = new RestRequest("/jsonsdk/TransactionSearchService/executeUserSearchRequest", Method.POST);
request.AddParameter("cobSessionToken", param.CobSessionToken);
request.AddParameter("userSessionToken", param.UserSessionToken);
request.AddParameter("transactionSearchRequest.containerType", param.ContainerType);
request.AddParameter("transactionSearchRequest.higherFetchLimit", param.HigherFetchLimit);
request.AddParameter("transactionSearchRequest.lowerFetchLimit", param.LowerFetchLimit);
request.AddParameter("transactionSearchRequest.resultRange.endNumber", param.EndNumber);
request.AddParameter("transactionSearchRequest.resultRange.startNumber", param.StartNumber);
request.AddParameter("transactionSearchRequest.searchFilter.currencyCode", param.CurrencyCode);
request.AddParameter("transactionSearchRequest.searchFilter.postDateRange.fromDate", param.FromDate);
request.AddParameter("transactionSearchRequest.searchFilter.postDateRange.toDate", param.ToDate);
request.AddParameter("transactionSearchRequest.searchFilter.transactionSplitType.splitType", param.SplitType);
request.AddParameter("transactionSearchRequest.ignoreUserInput", param.IgnoreUserInput);
request.AddParameter("transactionSearchRequest.searchFilter.itemAcctId", param.ItemAcctId);
var response = RestClientUtil.GetBase().Execute(request);
var content = response.Content;
return new YodleeServiceResultDto(content);
As per the response from shreyans in this posting Getting Error "Any one of [**] of transactionSearchFilter cannot be NULL OR Invalid Values I am not putting in the ClientId and the ClientName
The documentation doesn't specify the format of the dates but the example seems to tell me that its american date format. And specifies a parameter saying IgnoreUserinput, but doesnt have a parameter for user input so this is confusing
When I make a call using this format I get an error response
var getSearchResult = yodleeExecuteUserSearchRequest.Go(yodleeExecuteUserSearchRequestDto);
getSearchResult.Result="
{"errorOccured":"true","exceptionType":"Exception Occured","refrenceCode":"_60ecb1d7-a4c4-4914-b3cd-49182518ca5d"}"
But I get no error message in this and I have no idea what I have done wrong or where to look up this error, can somebody who has used Yodlee REST Api point me in the right direction as I need to get this researched quickly....
thanks your your help, advice, corrections and pointers....
Here is the list of parameters which you can try
1) For a specific ItemAccountId all transactions
transactionSearchRequest.containerType=all
transactionSearchRequest.higherFetchLimit=500
transactionSearchRequest.lowerFetchLimit=1
transactionSearchRequest.resultRange.startNumber=1
transactionSearchRequest.resultRange.endNumber=500
transactionSearchRequest.searchClients.clientId=1
transactionSearchRequest.searchClients.clientName=DataSearchService
transactionSearchRequest.searchFilter.currencyCode=USD
transactionSearchRequest.searchClients=DEFAULT_SERVICE_CLIENT
transactionSearchRequest.ignoreUserInput=true
transactionSearchRequest.ignoreManualTransactions=false
transactionSearchRequest.searchFilter.transactionSplitType=ALL_TRANSACTION
transactionSearchRequest.searchFilter.itemAccountId.identifier=10000353
2) For a Specific account (itemAccountId) with start and end dates
transactionSearchRequest.containerType=all
transactionSearchRequest.higherFetchLimit=500
transactionSearchRequest.lowerFetchLimit=1
transactionSearchRequest.resultRange.startNumber=1
transactionSearchRequest.resultRange.endNumber=500
transactionSearchRequest.searchClients.clientId=1
transactionSearchRequest.searchClients.clientName=DataSearchService
transactionSearchRequest.searchFilter.currencyCode=USD
transactionSearchRequest.searchClients=DEFAULT_SERVICE_CLIENT
transactionSearchRequest.ignoreUserInput=true
transactionSearchRequest.ignoreManualTransactions=false
transactionSearchRequest.searchFilter.transactionSplitType=ALL_TRANSACTION
transactionSearchRequest.searchFilter.itemAccountId.identifier=10000353
transactionSearchRequest.searchFilter.postDateRange.fromDate=08-01-2013
transactionSearchRequest.searchFilter.postDateRange.toDate=10-31-2013

Negative Testing for PayPal using Sandbox with VB.NET - how to simulate different scenarios?

I have a website written in VB.NET that implements PayPal for payments. This is all working fine for successful payments, but I need to be able to simulate scenarios of a failed transaction, pending transaction, etc.
I have read the documentation, which starts on page 47. I enabled Negative Testing in a business account that I created in a Sandbox, but I am not getting desired results.
To simulate an error, as specified in the documentation, I'm passing an error code to Token, which is then used in a request to DoExpressCheckoutPayment - code below - but instead of this raising the error 10417, the response says Invalid Token:
Dim oldToken As String
With RequestDetails
oldToken = .Token
.Token = "10417"
End With
Dim request As New DoExpressCheckoutPaymentRequestType
request.DoExpressCheckoutPaymentRequestDetails = RequestDetails
Dim response As DoExpressCheckoutPaymentResponseType
response = DirectCast(caller.Call("DoExpressCheckoutPayment", request),
DoExpressCheckoutPaymentResponseType)
Questions:
What am I doing wrong in the code above so that I can't trigger a correct error?
How do I simulate a response where the status is Pending, Processed, Failed, etc.?
I was testing this about a week ago and was receiving the same problem, now, I no longer receive an error:
API Request:
METHOD=DoExpressCheckoutPayment
VERSION=82
token=10755
PayerID=GNT5WLV6WKLYW
PAYMENTACTION=Sale
AMT=456
PAYMENTREQUEST_0_AMT=458
PAYMENTREQUEST_0_ITEMAMT=458.00
PAYMENTREQUEST_0_SHIPPINGAMT=20.00
PAYMENTREQUEST_0_TAXAMT=46.20
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_DESC=test EC payment
L_PAYMENTREQUEST_0_NAME0=Books
L_PAYMENTREQUEST_0_AMT0=154.00
L_PAYMENTREQUEST_0_NUMBER0=ABC123
L_PAYMENTREQUEST_0_QTY0=2
L_PAYMENTREQUEST_0_NAME1=CDs
L_PAYMENTREQUEST_0_AMT1=50.00
L_PAYMENTREQUEST_0_NUMBER1=BY-Z4736
L_PAYMENTREQUEST_0_QTY1=3
API Response:
TIMESTAMP=2011-09-27T20:39:57Z
CORRELATIONID=13126abeb4615
ACK=Failure
VERSION=82
BUILD=2133933
L_ERRORCODE0=10755
L_SHORTMESSAGE0=Unsupported Currency.
L_LONGMESSAGE0=Currency is not supported
L_SEVERITYCODE0=Error
I did find an article on x.com that deals with this issue as well.

phpBB: PHP code to automate forum post and private message sending

I have a phpBB forum and would like to write an external class which can be used to send private messages to some of the users of the forum.
Also, I'd like to automate the process of sending a post on the forum since some automatic notifications can thus be included in it.
Something along the lines:
PhpbbControl::sendPM(Integer $from_user, Array $to_users, String $content);
// ^ sends a new private message, returns false on failure
PhpbbControl::newPost(Integer $forum_id, Integer $from_user, String $content);
// ^ creates a new post on a given forum, returns false on failure
Any ideas or known MODs to provide that?
Thanks
In a MOD I wrote I needed to send a PM. Dualfusion (another phpBB MODder), wrote a function to do just that. You can find it Here (Lines 48 - 147).
I don't have any knowledge of a newPost function (I left the MODding scene a while ago), but It shouldn't be too hard to write one up. You can model it on the PM function, and figure out the tables you need to edit.