import config from "$config"; import { g, s } from "$lib/db"; import { fiat } from "$lib/utils"; import { SquareClient } from "square"; import { v4 } from "uuid"; const { appId, environment } = config.square; export const squarePayment = async (p, user) => { let square = await g(`${user.id}:square`); if (!(square && user.syncSquare)) return; let client = new SquareClient({ environment, }); const { refreshToken } = square; square = await client.oAuth.obtainToken({ clientId: appId, grantType: "refresh_token", refreshToken, }); await s(`${user.id}:square`, square); const { accessToken } = square; client = new SquareClient({ token: accessToken, environment, }); const locs = await client.locations.list({}); await client.payments.create({ sourceId: "EXTERNAL", idempotencyKey: v4(), amountMoney: { amount: BigInt(parseFloat(fiat(p.amount, p.rate).toFixed(2)) * 100), currency: p.currency, }, tipMoney: p.tip ? { amount: BigInt(parseFloat(fiat(p.tip, p.rate).toFixed(2)) * 100), currency: p.currency, } : undefined, autocomplete: true, externalDetails: { type: "OTHER", source: `Coinos payment ${p.id}` }, locationId: locs.locations[0].id, referenceId: v4(), note: `Coinos payment ${p.id}`, }); }; nversions'>conversions coinos server — legacy coinos.io backend (Lightning, on-chain, Liquid)coinos
aboutsummaryrefslogtreecommitdiffstats
path: root/socket_test.coffee
blob: 315be3a3386f040908ce25b9f6d9237c571e5964 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  transaction = {"hash":{},"version":1,"lock_time":0,"ins":[{"s":{},"q":4294967295,"o":{}}],"outs":[{"v":{},"s":{}},{"v":{},"s":{}}],"_buffer":{},"txid":"8500a0893a2d83a17819673884ade21bbef07d8c92bfe51682e45873cc2d3720","vin":[{"n":0,"txid":"1549415465c84fb519ffb92339ef80461427502c90d5d3ac5d01f27d824feabd","vout":1}],"vout":[{"valueSat":10000,"scriptPubKey":{"addresses":["1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr"]},"n":0},{"valueSat":3966838180,"scriptPubKey":{"addresses":["1Ao8Swc6vSosrjednQkNZeXEXVu1ZcxYZE"]},"n":1}],"time":1405573125}

  $('body').append(transaction.vout[0].valueSat)

  socket = io('ws://insight.bitpay.com')
  socket.on('connect', ->
    $('body').append('connected')
    this.emit('subscribe', '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr')
  )

  socket.on('1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr', (data) ->
    $('body').append(JSON.stringify(data))
  )