1
votes

I do the following in ColdFusion script:

svc = new http();
svc.setMethod('post');
svc.setCharset('utf-8');
svc.setUrl('https://api.stripe.com/v1/charges');
svc.addParam(type='header', name='Authorization', value='Bearer #Stripe.mySecretKey#');
svc.addParam(type='formfield', name='amount', value=form.amount);
svc.addParam(type='formfield', name='currency', value='usd');
svc.addParam(type='formfield', name='card', value='#form.card#');
svc.addParam(type='formfield', name='description', value='#form.email#');
prefix = svc.send().getPrefix();
response = prefix.FileContent;
WriteOutput(response & '<br>');
WriteOutput(IsSimpleValue(response) & '<br>');
WriteOutput(IsJSON(response));
dump(response);

And I'm getting a string that looks like this:

{ "id": "ch_6HAwRK92OsQPoA", "object": "charge", "created": 1432149035, "livemode": false, "paid": true, "status": "paid", "amount": 100, "currency": "usd", "refunded": false, "source": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "captured": true, "card": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "balance_transaction": "txn_6HAw4bAUUZ6trA", "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "[email protected]", "dispute": null, "metadata": {}, "statement_descriptor": null, "fraud_details": {}, "receipt_email": null, "receipt_number": null, "shipping": null, "destination": null, "application_fee": null, "refunds": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/charges/ch_6HAwRK92OsQPoA/refunds", "data": [] } }

As well as "YES" and "YES".

If I do a DeserializeJSON(response), then I get a 500 error.

So, how do I put this simple value string, which looks like json, in a ColdFusion structure so that I can reference response.id and response.paid?

1

1 Answers

3
votes

Something's wrong in your CF or web server setup.

I tested your json with CF11 on tryCF and it works.

<cfscript>

json = '{ "id": "ch_6HAwRK92OsQPoA", "object": "charge", "created": 1432149035, "livemode": false, "paid": true, "status": "paid", "amount": 100, "currency": "usd", "refunded": false, "source": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "captured": true, "card": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "balance_transaction": "txn_6HAw4bAUUZ6trA", "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "[email protected]", "dispute": null, "metadata": {}, "statement_descriptor": null, "fraud_details": {}, "receipt_email": null, "receipt_number": null, "shipping": null, "destination": null, "application_fee": null, "refunds": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/charges/ch_6HAwRK92OsQPoA/refunds", "data": [] } }';

writeOutput(isJSon(json));
writeDump(DeserializeJSON(json));

</cfscript>

Run: http://trycf.com/gist/cb798ff697ac80396284/acf11