Last active
September 30, 2017 17:21
-
-
Save darwin/64600b52a61f01bd2a6ab21de69aec47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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