Skip to content

Instantly share code, notes, and snippets.

@darwin
Last active September 30, 2017 17:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darwin/64600b52a61f01bd2a6ab21de69aec47 to your computer and use it in GitHub Desktop.
Save darwin/64600b52a61f01bd2a6ab21de69aec47 to your computer and use it in GitHub Desktop.
(ns cljs.stripe
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [<! chan put!]]
[oops.core :refer [gcall!]]))
; Stripe.piiData.createToken({
; personal_id_number: $('.personal_id_number').val()
; }, stripeResponseHandler);
; a simple wrapper
(defn make-callback-from-channel [channel]
(fn [& args]
(put! channel (or args '()))))
(defn create-token! [ssn]
(let [channel (chan)
request (js-obj "personal_id_number" ssn)]
(gcall! "Stripe.piiData.createToken" request (make-callback-from-channel channel))
channel))
; usage example
(defn do-something-useful-with-stripe! [ssn]
(go
(let [[status response] (<! (create-token! ssn))]
(println status response))))
; -- main
(go
(<! (do-something-useful-with-stripe! "42")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment