我正在使用 Stripe 处理付款。我有一个平台,国际 Connect 帐户可以通过我的平台向其他人出售物品。
我的平台是美元。在此特定示例中,Connect 帐户采用 CAD(加拿大元)。当有人从此 CAD Connect 帐户购买商品时,Stripe 会将钱存入我的平台帐户,将我的应用程序费用留在那里,然后将正确的金额转入 CAD Connect 帐户。它将这个金额转换为加元。在 stripe GUI 中,我可以找到以 CAD 表示的汇率和转账金额,如下面的屏幕截图所示。但我在 API 中找不到这些属性。
我见过的唯一具有exchange_rate属性的对象是余额交易。但是,当我获取屏幕截图中交易的余额交易时,我得到以下响应对象:
请求: https://api.stripe.com/v1/balance_transactions/txn_1IBNiNLLBOhef2QNqIeaNg9o
回复:
{
"id": "txn_1IBNiNLLBOhef2QNqIeaNg9o",
"object": "balance_transaction",
"amount": -7777,
"available_on": 1611619200,
"created": 1611076199,
"currency": "usd",
"description": null,
"exchange_rate": null,
"fee": 0,
"fee_details": [],
"net": -7777,
"reporting_category": "transfer",
"source": "tr_1IBNiNLLBOhef2QNcNqv3IlS",
"status": "pending",
"type": "transfer" }
Run Code Online (Sandbox Code Playgroud)
这里的问题是上面的余额交易对象仅以美元显示此交易:77.77 美元来自我的平台帐户。
但它不显示兑换率或加元金额。当这 77.00 美元进入 CAD Connect 账户时,正如我们在 GUI 屏幕截图中看到的那样,77.77 美元被转换为 …
我尝试用 Brew 升级
$ brew upgrade stripe/stripe-cli/stripe
Run Code Online (Sandbox Code Playgroud)
我有:
Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.
Run Code Online (Sandbox Code Playgroud)
按照建议,我尝试过
$ arch -arm64 brew install
Run Code Online (Sandbox Code Playgroud)
但得到:
Error: Invalid usage: This command requires at least 1 formula or cask argument.
Run Code Online (Sandbox Code Playgroud)
我尝试根据本教程安装 Rosetta 2
$ /usr/sbin/softwareupdate --install-rosetta --agree-to-license
Run Code Online (Sandbox Code Playgroud)
但我得到了:
Installing Rosetta 2 on this system is not supported.
Run Code Online (Sandbox Code Playgroud) 我正在使用 apihttp://exchangeratesapi.io/来获取汇率。
他们的网站询问:
请尽可能缓存结果,这将使我们能够在没有任何速率限制或 API 密钥要求的情况下保持服务。
-来源
然后我发现了这个:
默认情况下,对 Exchangeratesapi.io API 的所有请求的响应都会被缓存。这可以显着提高性能并减少服务器的带宽。
- github上某人的项目,不确定是否准确
我以前从未缓存过某些东西,这两个语句让我很困惑。当 API 的网站说“请缓存结果”时,听起来缓存是我可以在请求中fetch或以某种方式在前端执行的操作。例如,将结果存储在本地存储中的某种方式。但我找不到任何有关如何执行此操作的信息。我只找到了有关如何强制响应不缓存的资源。
第二个引言听起来好像缓存是 API 在其服务器上自行执行的操作,因为它们将响应设置为自动缓存。
如何按照 api 站点的要求缓存结果?
When we make a stripe checkout session we include a success url:
session = await this.stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: lineItems,
payment_intent_data: {
transfer_data: {
amount: 9999999,
destination: someaccountId,
},
},
success_url: `http://localhost:4000/api/checkout/success?true&session_id={CHECKOUT_SESSION_ID}&alias_id=${aliasId}`,
cancel_url: `http://localhost:4000/api/checkout/canceled?session_id={CHECKOUT_SESSION_ID}`,
});
Run Code Online (Sandbox Code Playgroud)
The success URL is where stripe sends the user after a successful payment. It's a GET request since stripe is redirecting the user. Many apps using stripe will need to take actions after a successful checkout- sending an email receipt, notifications, sending paid content, updating …
有时,突变观察者回调不会在我期望的时候触发。
如果我在开发人员工具控制台中运行此代码:
// callback for mutations observer
callbackForAllChanges = function (mutationsList, observer) {
console.log("mutations: ", mutationsList);
};
// create mutation observer
allChanges = new MutationObserver(callbackForAllChanges);
// attach mutation observer to document
allChanges.observe(document, {
childList: true,
subtree:true
});
// create new child
document.body.appendChild(document.createElement("div"));
Run Code Online (Sandbox Code Playgroud)
我希望当我创建一个新的孩子时回调会触发。但有时会,有时不会。
当我在 stackoverflow 上的 devtools 控制台中运行代码时,它可以工作:我看到mutations: [MutationRecord]已记录到控制台。
当我在twitter上并在 devtools 控制台中运行上述代码时,它似乎不起作用:mutations: [MutationRecord]未记录到控制台。
什么可能导致 Mutation Observer 在 Twitter 上无法工作?
mutations: [MutationRecord]没有日志我无法获取发送 cookie 的信息。我读到对于跨源请求,您必须使用credentials: 'include'. 但这仍然没有给我饼干。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div>fetch on load</div>
<script>
fetch('http://localhost:4001/sayhi', { credentials: 'include' })
.then((res) => {
return res.text();
})
.then((text) => {
console.log('fetched: ' + text);
})
.catch(console.log);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
const express = require('express');
const mongoose = require('mongoose');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const app = express();
const cors = require('cors');
app.use(cors());
app.use((req, …Run Code Online (Sandbox Code Playgroud) #gradient_div我有一个 id为background-image的div linear-gradient。仅在某些浏览器窗口宽度下,线性渐变的末尾和 div 的末尾之间才会出现间隙#gradient_div。当我拉伸和缩小浏览器窗口时,这条白线消失并重新出现。
看起来它与边距有关:
当我将边距设置为 时margin: 0 1%;,白线会出现在特定的窗口宽度处。
在1%时,只要窗口宽度在68-92 范围内结束,就会出现白线,例如:4 68 px-4 92 px、5 68 px-5 92 px、6 68 px-6 92 px 等。
对于其他页边距左侧和右侧百分比,该线显示在以下页面宽度处:
2% :页面宽度以 92-_04 和 42-54 范围结尾
3% :页面宽度以 34-41、67-74 和 00-08 范围结尾
30%:页面宽度以 5 或 8 结尾
当我将背景设置为颜色而不是渐变时,或者当我将背景设置为图像时,不存在白线问题;更新当边距设置为 px 时,也不会发生这种情况。background: blue;background-image
欢迎提出解决此问题的建议,但我最感兴趣的是了解为什么会发生这条线。这是什么原因造成的?
#gradient_div{
background-image: linear-gradient(to right, rgba(0, 126, 255, 0.86) , rgb(152, 4, 228));
height: …Run Code Online (Sandbox Code Playgroud)我有一个样式化的 Material UI 按钮组件。我想做到这一点,以便当我单击样式按钮时我可以选择计算机上的文件。
我认为这可以通过将for a (文件输入)元素放置在<Button></Button>内部来完成 。但这似乎只适用于 div 而不是按钮。我既无法为常规按钮元素打开文件选择器,也无法为材质 UI 按钮组件打开文件选择器。<label><input type="file"/>
如何让材质 uiButton充当文件输入的标签?
import React from 'react';
import { Button } from '@material-ui/core';
export default function InputButton() {
return (
<div>
{/* Button does not open file picker window */}
<div>
<label>
<input type="file" style={{ display: 'none' }} />
<Button>upload file</Button>
</label>
</div>
{/* div does open file picker window */}
<div>
<label>
<input type="file" style={{ display: 'none' }} />
<div>upload file</div> …Run Code Online (Sandbox Code Playgroud) 我遇到堆内存错误,导致我的应用程序崩溃。但我的应用程序有可用内存。
\n app/web.1 [4:0x4ea2840] 27490 ms: Mark-sweep 505.7 (522.4) -> 502.2 (523.1) MB, 440.3 / 0.0 ms (average mu = 0.280, current mu = 0.148) allocation failure scavenge might not succeed \nRun Code Online (Sandbox Code Playgroud)\napp/web.1 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory \nRun Code Online (Sandbox Code Playgroud)\n错误发生在 512mb 左右。我的标准 2X 测功机有 1GB。
\n节点版本是16.17.0。据我了解,超过 12 的节点版本的堆限制基于可用内存。
\n\n\n>= 12 的 Node 版本可能不需要使用 --optimize_for_size 和 --max_old_space_size 标志,因为 JavaScript 堆限制将基于可用内存。\n src
\n
我考虑了 512mb 测功机上的一名工人。但是worker dyno会导致整个应用程序崩溃吗?如果是这样的话,错误不会来自app/worker.1 …
当我在 vscode 中运行调试器时,出现以下错误:
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
Run Code Online (Sandbox Code Playgroud)
我意识到这是因为调试器无法访问我的.env文件。我的数据库 uri 存储在我的.env文件中。所以调试器看不到它。
如何让调试器访问我的.env文件变量?
如何将 json 与图像文件一起以 Express 方式发送?
我了解您使用以下方式提供图像res.sendFile
const path = require('path');
app.get('/image/:filename', (req, res, next) => {
res.type('png');
res.sendFile(
path.resolve(`${path.join(__dirname, './data/images')}/${req.params.fileName}`)
);
});
Run Code Online (Sandbox Code Playgroud)
但是如果你想在图像中包含 json 该怎么办?例如,如果您正在提供用户的个人资料数据(名称、信息等)以及个人资料图像。
const path = require('path');
app.get('/user/:id', async (req, res, next) => {
const { id } = req.params;
let user;
try {
user = await userService.getUser(id);
} catch (err) {
return next(err);
}
/* user:
* {
* name: "Dash",
* location: "Chicago",
* profilePicture: '5c751e73-a7bc-47c4-b2a5-4ac902e7a2ce.png'
* }
*/
// what next????
}); …Run Code Online (Sandbox Code Playgroud) 使用 Twitter API,我试图代表 Twitter 用户发布一条推文。
我正在使用节点和passport-twitter和twit模块。
一些资源:
我按照上面的教程成功通过了passport-twitter 的身份验证。
我还在我的 Twitter 开发者帐户上使用 twit成功发布了帖子。
但是,我无法将这两件事结合起来;试图代表另一个用户在 Twitter 上发帖。为此,我需要获取用户的访问令牌和访问令牌秘密。然后,我需要使用该信息向 Twitter API 发出发布请求。
我不确定将 post 请求放在 Passport-twitter 代码的何处。我尝试将它放在第二个路由中,这是 Twitter 在用户登录后将用户重定向到的 URL。
app.get('/twitter/login', passport.authenticate('twitter'))
app.get('/twitter/return', passport.authenticate('twitter', {
failureRedirect: '/'
}), function(req, res) {
//Post using twit
//grab access token and access token secret from the request query
const access_token …Run Code Online (Sandbox Code Playgroud) 我有Orders 和Shops。
db={
"orders": [
{
"_id": 1,
"shop": 1,
"price": 11
},
{
"_id": 2,
"shop": 2,
"price": 101
},
],
"shops": [
{
"_id": 1,
},
{
"_id": 2,
},
{
"_id": 3,
},
],
}
Run Code Online (Sandbox Code Playgroud)
我想找出哪些商店的订单数为0。
我是这样做的
db.shops.aggregate([
{
$lookup: {
from: "orders",
let: {
shop: "$_id"
},
pipeline: [
{
$match: {
$expr: {
$eq: [
"$shop",
"$$shop"
]
},
},
},
],
as: "orders",
},
},
{
$project: {
user: "$user", …Run Code Online (Sandbox Code Playgroud)