Fork me on GitHub
#hoplon
<
2016-04-28
>
leontalbot08:04:05

Has anyone used stripe with hoplon?

leontalbot08:04:48

Couldn't find any example online

leontalbot09:04:27

But even in vanilla clojurescript can't find anything...

dm309:04:52

have you tried with Hoplon?

leontalbot09:04:54

Yes and i'm very far from having a payment form

leontalbot09:04:05

@dm3 Actually cljsjs.stripe doesn't load properly. (Can't find namespace)

leontalbot09:04:14

But that aside wouldn't be sure how to convert the following in hoplon

dm309:04:23

I see that it was added by @rwillig - who is a Hoplon user IIRC

leontalbot09:04:01

@dm3 Interesting! Is he on Slack too?

dm309:04:30

I thought I saw him here

dm309:04:55

I'd try creating a minimal cljs Hoplon/Stripe project

dm309:04:07

and just adding stripe sources directly for a start

leontalbot09:04:01

Excellent, yes! Will do

levitanong09:04:16

Hey guys. Just some musing: Say you make a record in the server, and it’s served to the client. Would the record’s methods still be available on the client?

leontalbot09:04:32

@dm3 So here I only add cljsjs lib and require it at index.cljs.hl

dm309:04:24

and do you see Stripe javascript in the sources?

leontalbot09:04:42

And I get this when building...

ERROR: No such namespace: cljsjs.stripe, could not locate cljsjs/stripe.cljs, cljsjs/stripe.cljc, or Closure namespace "cljsjs.stripe" in file /Users/leontalbot/.boot/cache/tmp/Users/leontalbot/Dropbox/Sites/hoplon-stripe/1d8/62mkia/hoplon/app_pages/_index_DOT_html.cljs at file hoplon/app_pages/_index_DOT_html.cljs

leontalbot09:04:49

@dm3 Not sure I get your question...

dm309:04:02

that's strange

leontalbot09:04:01

Maybe I should ask to #C0E66E1H7 channel

dm309:04:22

it's a bad artefact

dm309:04:29

there's no Stripe sources in there

dm309:04:51

META-INF/MANIFEST.MF
META-INF/maven/cljsjs/stripe/
META-INF/maven/cljsjs/
META-INF/maven/
META-INF/
META-INF/maven/cljsjs/stripe/pom.xml
deps.cljs
cljsjs/common/
cljsjs/
cljsjs/common/stripe.ext.js
META-INF/maven/cljsjs/stripe/pom.properties

dm309:04:05

try including stripe javascript directly

dm309:04:11

and copying the externs file

levitanong09:04:46

@leontalbot: time to experiment

raywillig14:04:37

hi @leontalbot @dm3 i just got online, saw your discussion about stripe. as a matter of fact, i’m just wrapping up a new project using stripe and hoplon

leontalbot14:04:25

Would you mind showing a minimal example?

raywillig14:04:01

so the thing with the cljsjs stripe is that the stripe js not available to be downloaded. it works similarly to the google maps component for hoplon

raywillig14:04:16

that’s the basic idea of the the gist that you looked at

raywillig14:04:41

cljsjs stripe basically just provides the ext file so you can compile in advanced mode

raywillig14:04:57

let me look at the code and i’ll see what i can post

leontalbot14:04:36

I was there

(def stripe-script-url "")
(defc stripe-pub-key "")
(defc stripe-ready? nil)

(defn stripe-init! []
  (do
    (.setPublishableKey js/Stripe @stripe-pub-key)
    (reset! stripe-ready? true)))

(defn ensure-stripe []
  (.getScript js/jQuery stripe-script-url #(stripe-init!)))

(with-init! (ensure-stripe))

raywillig14:04:20

this is a little more involved. I’m using a form state machine thing that @micha was nice enough to post one time and so I had to do a few extra things to coordinate with it

raywillig14:04:16

@leontalbot: i have a call in about 15 minutes but i can review it with you after. or just post any questions you have and I’ll try to answer

leontalbot14:04:47

excellent! Much thanks!

raywillig14:04:50

it’s also a little more complicated by the fact that this app is handling stripe transactions for multiple organizations so it receives its stripe credentials from a castra endpoint

raywillig14:04:13

so I needed to defer the initialization stuff until the state cell is populated

leontalbot14:04:44

@raywillig So far : Where can I find spy->> source? Could you provide an idea of core/state structure?

leontalbot14:04:48

(if possible)

dm315:04:13

@raywillig: would be cool if you could add some explanation to cljsjs/stripe/README.md

leontalbot17:04:53

@raywillig: Would you be available for questions?

raywillig18:04:37

@leontalbot: sure, just got back from lunch so catch me before i doze off

leontalbot18:04:57

@raywillig: This would be my first attempt

leontalbot18:04:01

Does not work

leontalbot18:04:20

Wanted to get your feedback before moving on

leontalbot18:04:24

much thanks!

leontalbot18:04:06

update: input-fields now working

leontalbot18:04:28

Updated. Now when I submit, I get : "A network error has occurred, and you have not been charged. Please try again."

leontalbot18:04:04

Maybe it sends twice?

raywillig19:04:52

are you able to login to your stripe account and see what got in there?

leontalbot19:04:09

nothing in the logs

raywillig19:04:08

well, the thing is that stripe just returns back a token. you’d need to then send that token to your server component to complete a transaction using your stripe secret key. have you done that part?

leontalbot19:04:32

no this part is still missing

raywillig19:04:37

have you looked at the js examples on the strip docs?

raywillig19:04:56

so the only thing you can really verify with this is that you get back a stripe token

leontalbot19:04:18

The thing is, stripe doesn't return a token

raywillig19:04:59

i think your .createToken handler function could be a problem

raywillig19:04:39

stripe is going to call the callback with only two parameters - status and response

raywillig19:04:07

so if you want your response handler to be aware of that third argument you should make your response handler arg signature look something like [form-data status response] and then the callback should look like #(partial strip-response-handler @form-data)

leontalbot19:04:27

@raywillig: Thanks! I finally get smth in the logs

leontalbot19:04:50

@raywillig: Oups, I can't assoc the token though

leontalbot19:04:01

(defn handle-stripe-response [form-data status response]
  (let [r (js->clj response :keywordize-keys true)]
    (if (= status 200)
      (do (swap! form-data assoc :token r)
          (reset! form-data-ok? true)
          #_"FIXME send to server with cljs/http"
          #_"FIXME change view")
      (reset! error-message (-> r :error :message) {}))))

leontalbot19:04:22

(swap! form-data assoc :token r) doesn't seem to work 😞

raywillig19:04:53

does the :token key get created in form-data?

raywillig19:04:02

or does it throw and exception?

raywillig19:04:10

*an exception

leontalbot19:04:21

no exception, but no assoc

raywillig19:04:37

what do you see if you log response to console?

leontalbot19:04:38

(.createToken (.-card js/Stripe) (clj->js data)
                  (partial handle-stripe-response form-data))

leontalbot19:04:50

not #(partial...)

raywillig19:04:36

oh right partial returns a function

leontalbot19:04:47

Thanks a lot @raywillig ! First step completed!