braintree / braintree_node

Braintree Node.js library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
334 stars 104 forks source link

Deno Braintree #218

Closed do4Mother closed 1 year ago

do4Mother commented 1 year ago

General information

Issue description

i'm having trouble integrating Braintree payments using Deno. When I try to create a transaction with a payment method and create a customer. I get an error from the log like this.

TypeError: B.setTimeout is not a function
    at https://esm.sh/v104/braintree@3.13.0/X-ZHN2LzAuMTMyLjA/deno/braintree.js:2:11960
    at new Promise (<anonymous>)
    at Je.httpRequest (https://esm.sh/v104/braintree@3.13.0/X-ZHN2LzAuMTMyLjA/deno/braintree.js:2:11184)
    at Je.<anonymous> (https://esm.sh/v104/@braintree/wrap-promise@2.1.0/X-ZHN2LzAuMTMyLjA/deno/wrap-promise.js:2:1479)
    at Je.post (https://esm.sh/v104/braintree@3.13.0/X-ZHN2LzAuMTMyLjA/deno/braintree.js:2:10463)
    at Je.<anonymous> (https://esm.sh/v104/@braintree/wrap-promise@2.1.0/X-ZHN2LzAuMTMyLjA/deno/wrap-promise.js:2:1479)
    at Ur.create (https://esm.sh/v104/braintree@3.13.0/X-ZHN2LzAuMTMyLjA/deno/braintree.js:22:19972)
    at Ur.<anonymous> (https://esm.sh/v104/@braintree/wrap-promise@2.1.0/X-ZHN2LzAuMTMyLjA/deno/wrap-promise.js:2:1479)
    at Ur.sale (https://esm.sh/v104/braintree@3.13.0/X-ZHN2LzAuMTMyLjA/deno/braintree.js:22:20894)
    at Ur.<anonymous> (https://esm.sh/v104/@braintree/wrap-promise@2.1.0/X-ZHN2LzAuMTMyLjA/deno/wrap-promise.js:2:1479)

and here it's my source code

import braintree from "https://esm.sh/braintree@3.13.0?target=deno&no-check";

export const gateway = new braintree.BraintreeGateway({
  environment: braintree.Environment.Sandbox,
  merchantId: Deno.env.get("BRAINTREE_MERCHANT_ID") ?? "",
  publicKey: Deno.env.get("BRAINTREE_PUBLIC_KEY") ?? "",
  privateKey: Deno.env.get("BRAINTREE_PRIVATE_KEY") ?? "",
});
const result = await gateway.transaction.sale({
        amount: "10",
        customer: {
          id: user.id,
          email: user.email ?? "",
        },
        paymentMethodNonce: nonce,
        deviceData: deviceData,
      });
hollabaq86 commented 1 year ago

👋 @do4Mother I believe the root of the issue is that Deno is a modern runtime for JavaScript and TypeScript, and this library doesn't support Typescript yet (see #176).

Since we don't develop the Deno library, we can't really offer much support, but maybe the Deno community might be able to offer some help for interacting with libraries that don't yet have Typescript support. I did see they have a --no-check option in their docs that might skip type checking.

I'm going to close this issue since we're tracking the root cause (Typescript support) in the issue previously mentioned.

crookedneighbor commented 1 year ago

My guess is that Deno's version of the http/https modules don't include a setTimeout function. https://github.com/braintree/braintree_node/blob/451e665f3a87de88f99281db225f0d9b99cbe33a/lib/braintree/http.js#L4-L5

crookedneighbor commented 1 year ago

https://github.com/braintree/braintree_node/blob/451e665f3a87de88f99281db225f0d9b99cbe33a/lib/braintree/http.js#L187