Closed gpickin closed 9 years ago
Can you tell me what call you were making that was failing here and what version of the Stripe API you are using (you can see it in your dashboard)? I ask because I use this every day and am not running into problems.
Morning Brian.
Thanks for getting back to me. Here is what you asked for, plus some sample code, and my insight.
I am in test mode, and my api version is "2014-05-19”
I was making a simple call. I uses the checkout.js form. It gives me a card token.
Here is my code.
cfg = { path = "stripe.stripe", TestSecretKey = "sk_test_g83YAgQ0cP994HHwljtSjAkq" }; svc = createObject("component", "cfpayment.api.core").init(cfg); gw = svc.getGateway(); money = svc.createMoney( numberformat(bookingPricesData.total_due_online*100, "9") ); account = svc.createToken( caller.attributes.STRIPETOKEN ); response = gw.purchase(money = money, account = account);
The error I got was saying invalid CUSTOMER… because it was expecting a card token, but the checkout.js async code gives you a card token. So I looked at the code, changed it to use CARD, since thats the token I have… and then it works.
I assume you’re getting a customer token? I guess I could do that, but it would be nice to work with just a simple card token too. Maybe we need a flag for the type of token we’re passing to createToken?
Maybe its my api, maybe its test mode. Thanks for getting back to me on this, I want to contribute, but obviously, if its working for you, we need to figure out the issue. I really like the idea of this project, since it seems to be a constant battle dealing with our payment code.
Thanks.
Gavin
On Jan 1, 2015, at 12:10 PM, Brian notifications@github.com wrote:
Can you tell me what call you were making that was failing here and what version of the Stripe API you are using (you can see it in your dashboard)? I ask because I use this every day and am not running into problems.
— Reply to this email directly or view it on GitHub.
Thanks Gavin - I'm using 2012-11-07 so definitely a few things have changed! I will run some tests and see if we should support both or simply update it to a more recent version of the API. I need to add marketplace support so I'll look if we might have backwards compatibility issues or what the right step is. Thanks for pointing this out!
I thought it might be something like this… I guess the question is… how many API changes have they made? We could have something for that, like a version, but if they update it often, wow, that could be a headache.
With as many uses as you have, the last thing you need is an update breaking people all the time. I was pulling my hair out trying to figure out why nothing was working… I thought I was crazy… at least this makes sense, just need to look at how many versions, and how to deal with it.
https://stripe.com/docs/upgrades
There have been many updates… its not like an annual things… but it not every update will affect users dramatically. I guess we could include logic that checks the api… and then makes the appropriate call, but it could get messy. One of the problems with code being used in a lot of places.
Let me know if you want to bounce ideas etc.
Thanks again for your work on this.
Gavin
On Jan 2, 2015, at 11:28 AM, Brian notifications@github.com wrote:
Thanks Gavin - I'm using 2012-11-07 so definitely a few things have changed! I will run some tests and see if we should support both or simply update it to a more recent version of the API. I need to add marketplace support so I'll look if we might have backwards compatibility issues or what the right step is. Thanks for pointing this out!
— Reply to this email directly or view it on GitHub.
I've created a test but I can't replicate the error you were receiving. Can you send me a full error dump? It may help to get these two outputs:
response.getRequestData() <- will require you're in test mode to work response.getResult()
And then if you're getting a non 200 OK response or other error message, let me know what those are.
Gavin - checking in to see if you can send me a full error dump to help me debug/diagnose?
Form Submission
struct FIELDNAMES SLOT_ID,PLAYERS,STRIPETOKEN,STRIPETOKENTYPE,STRIPEEMAIL PLAYERS 2 SLOT_ID 347 STRIPEEMAIL gavin@netxn.com STRIPETOKEN tok_15JuKO2kVmB69QDKcmsvxP4C STRIPETOKENTYPE card fuseaction pages.page id 1061 sf act_book response.getParsedResult
struct
error
struct
message No such customer: tok_15JuKO2kVmB69QDKcmsvxP4C
param customer
type invalid_request_error
response.getRequestData
struct
GATEWAY_URL https://api.stripe.com/v1/charges
HEADERS
struct
authorization Bearer sk_test_g83YAgQ0cP994HHwljtSjAkq
HTTP_METHOD post
PAYLOAD
struct
amount 400
currency usd
customer tok_15JuKO2kVmB69QDKcmsvxP4C
response.getResult
object of java.io.ByteArrayOutputStream Class Name java.io.ByteArrayOutputStream Methods Method Return Type close() void reset() void size() int toByteArray() byte[] toString(java.lang.String) java.lang.String toString(int) java.lang.String toString() java.lang.String write(int) void write(byte[], int, int) void writeTo(java.io.OutputStream) void Parent Class
Sorry it took so long to get back to this.
As you can see in this one, the token from the form says card, but its trying to push it as a customer. I am using checkout.js so maybe thats the issue, it returns a card token, not a customer… if it did, that would work great.
Maybe there is an option with checkout.js to give you a customer instead, that would be nice actually. Anyways, hope its more helpful.
Gavin =
Gavin, it turns out you can pass both a card or a customer to be charged, so the reality is that both of us are correct. We always take the token and turn it into a customer so my workflow was different but both are legit.
My team has implemented a major upgrade to the gateway to support new beta marketplace functionality as part of the 2015-02-18 release and we've also added support for charging either a card (which is now called "source") or a customer. See #9 for details.
Thanks for bringing this to my attention! I'm going to close this issue as we'll resolve it with #9
WARNING: I'm solving this with a BACKWARDS-INCOMPATIBLE CHANGE.
In short, when we expect an account in Stripe, it can be an existing token, a credit card or bank account dictionary. It can no longer be a customer, like I've been using it.
Instead, you can now pass a cfpayment token of the customer ID in the options struct named "customer". Old code:
token = core.createToken().setID(value-from-stripe-js);
customer = gw.store(account = token);
charge = gw.purchase(account = customer, money = core.createMoney(1000));
New code:
token = core.createToken().setID(value-from-stripe-js);
customer = gw.store(account = token);
charge = gw.purchase(money = core.createMoney(1000), options = {customer: customer});
For the Stripe Connect/Marketplace updates in #9 and subsequent improvements in #18, I'm making the methods all behave more consistently. Tokens mean tokens, not tokens OR customers.
FWIW, I did attempt to make the methods take either but there is no way without going to the Stripe API to determine what kind of token you have which would have negative performance implications. Right now they have prefixes like cus and tok but Stripe specifically says not to depend on those which eliminated that as an option.
The current API accepts "customer" or "card" when charging. The issue is, the code was identifying the payload token as a "customer", instead of a "card" and therefore creating a customer not found error. Updating the field from "customer" to "card" in the AddToken function and in the Process Function fixes this issue.