Fork me on GitHub
#clojurescript
<
2023-03-18
>
Clojuri0an05:03:42

I need help, I've been stuck on this for a while. I'm trying to call Stripe, using shadow-cljs (so npm), here's how I'm trying to do things

(ns invoice.backend.main
  (:require ["stripe" :as stripe]
            [cljs.core.async :refer [go]]
           [cljs.core.async.interop :refer-macros [<p!]]))                                     (def stripeKey "key")

(def stripeAccount "account-num")

(def stripe-authed (stripe/Stripe stripeKey))                                                                                               (def charge (stripe-authed/charges.retrieve ({stripeKey {:stripeAccount stripeAccount}})))
return error
Use of undeclared Var stripe-authed/charges

thheller06:03:12

symbols with a slash are either namespaces or namespace aliases. but striped-auth is a local var, it cannot be used as an alias. use (-> stripe-auth (.-charges) (.-retrieve #js {stripeKey #js {:stripeAccount stripAccount}}))

Clojuri0an07:03:23

Can you tell me where in the documentation this syntax is covered? I'm having a hard time finding it

Clojuri0an07:03:49

I found an entry for the threading macro under https://clojure.org/guides/threading_macros and https://clojure.org/guides/weird_characters , but am having trouble finding the entry for the - symbol (under reader?) https://clojure.org/reference/reader https://www.clojurescript.org/guides/reader (to be honest I'm having a difficult time navigating clojurescript's documentation. I don't think I could find the reader guide from the main index)

p-himik07:03:41

The .- is interop with the host - both in CLJ and in CLJS. Regarding / - it's here: https://clojurescript.org/about/differences#_host_interop

p-himik07:03:50

The interop syntax is not really documented on the website. Like many other things - because it's not that different from Clojure and it would be mostly repeating the stuff from (at least, such an explanation seems reasonable to me).

Clojuri0an08:03:59

I receive error that javascript literal keys must be strings or unqualified keywords. I think the datastructure

(.retrieve #js {stripeTrans #js {:stripeAccount stripeAccount}})
may not be correct, it is supposed to be formatted as
stripe.charges.retrieve('charge-id', { stripeAccount: 'account number' });                                                                         
I would think the solution would be
(-> stripe-auth (.-charges) (.-retrieve stripeTrans #js {:stripeAccount stripeAccount})))
However, this returns the error:
dot process access with args 
which i don't understand

p-himik08:03:20

The next to last code block is correct, apart from the small mistake - there should be no -. The .- is for accessing properties and just . without - (thheller made a mistake above) is for calling member functions. The error is opaque but it basically means that you are trying to pass arguments to a form that accesses a property. I definitely suggest reading CLJ docs on interop and CLJS cheatsheet on it as well.

2
Clojuri0an08:03:43

I'll read them, and the other docs too, as I'm still pretty green. I think that what thheller meant was that (.-charges) is necessary (rather than (.charges)). I think this is because charges isn't a member function but a property(?). The following did what I wanted:

(-> stripe-authed (.-charges) (.retrieve stripeTrans #js {:stripeAccount stripeAccount})))

p-himik08:03:37

That's right, yes.

2
Alejandro Buffery09:03:30

I have just discovered by chance pyscript, it would be cool to be able to do the same with clojure https://www.youtube.com/watch?v=vxqBm6_0vyk

p-himik09:03:11

Assuming I understood what you mean by "the same", we can already do that with https://github.com/babashka/scittle.

Alejandro Buffery09:03:08

Had no idea, I’ll check it out, thanksss !!!

Alejandro Buffery09:03:33

May I ask, what are people most using it for ?

borkdude09:03:19

To create a pinball game, among other things :) https://thegeez.net/static/pinball/pinball.html

borkdude09:03:56

You can also create a guestbook and use babashka as the server: https://github.com/kloimhardt/babashka-scittle-guestbook The benefit is not having to "build" anything, you can quickly prototype stuff

borkdude09:03:57

scittle also works in sites like codepen https://codepen.io/ordnungswidrig/pen/xxpPYNO

borkdude09:03:18

Here is an issue tracking what people are doing with it: https://github.com/babashka/scittle/issues/40

Alejandro Buffery09:03:24

wowwwww, you are chatGPT version 1 million, thanksss !!!

kenny13:03:08

Is it just happenstance that :rename works without :refer’ing the var? e.g., the following works (:require [re-frame.core :as rf :rename {reg-event-db edb}])

kenny13:03:56

The https://clojurescript.org/about/differences#_namespaces seem to imply that it should only work from the set of symbols referred.

p-himik13:03:35

What do you mean by "works"? Doesn't result in an exception, makes edb available, makes rf/edb available, something else?

p-himik13:03:17

FWIW, (require '[clojure.string :as str :rename {trim x}]) in CLJ doesn't throw and only makes str be available as an alias to clojure.string. The :rename part has no effect. In a CLJS Node-based REPL, that expression throws.

kenny15:03:32

Doesn’t result in an exception and makes edb available.

p-himik15:03:09

Yeah, seems like a happenstance - not something to be used.

skylize01:03:40

Where were you able to find :rename in the docs? I only know about it from StackOverflow.

phill10:03:32

:rename is documented for refer (https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/refer) and use, but I don't see it documented for require. Anyway, on that web page it seems that :rename is a "filter" applied to "all public vars" in the source namespace. If it's not already on http://ask.clojure.org for abatement, you should put it there or we should draw lots