金流
Briantree sandbox
setup Briantree account
generate API Key( get Merchant ID, Public Key, Private Key)
login Briantree –> API –> Generate New API Key –> get API key
![pic1](/2021/12/07/js-5/pic1.png)
![pic2](/2021/12/07/js-5/pic2.png)
set CVV
Fraud Management –> CVV –> CVV does not match (when provided) (N) –> For Any Transaction
![pic3](/2021/12/07/js-5/pic3.png)
![pic4](/2021/12/07/js-5/pic4.png)
new Merchant Account ID
Business –> new Sandbox Merchant Account –> set Merchant Account ID + currency
![pic5](/2021/12/07/js-5/pic5.png)
![pic6](/2021/12/07/js-5/pic6.png)
![pic7](/2021/12/07/js-5/pic7.png)
example code
- Merchant Account ID 是用來設定不同幣別
- clientToken 設定 merchantAccountId 可但若要顯示 支援 payment 的方式
- transaction 設定 merchantAccountId 才會歸到設定帳戶,若未指定 merchantAccountId 會使用 default account 和 貨幣
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52// ./controllers/braintree.js
const User = require("../models/user");
const braintree = require("braintree");
require("dotenv").config();
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,
merchantId: process.env.BRAINTREE_MERCHANT_ID,
publicKey: process.env.BRAINTREE_PUBLIC_KEY,
privateKey: process.env.BRAINTREE_PRIVATE_KEY,
});
exports.generateToken = (req, res) => {
// transaction 設定 merchantAccountId 就好,clientToken 可以不用設
// 但若要顯示 payment 的方式,就要設定
// gateway.clientToken.generate({}, function (err, response) {
gateway.clientToken.generate(
{ merchantAccountId: process.env.BRAINTREE_MERCHANT_ACCOUNT_ID },
function (err, response) {
if (err) {
res.status(500).send(err);
} else {
// console.log(response);
res.send(response);
}
}
);
};
exports.processPayment = (req, res) => {
let nonceFromTheClient = req.body.paymentMethodNonce;
let amountFromTheClient = req.body.amount;
// charge
let newTransaction = gateway.transaction.sale(
{
amount: amountFromTheClient,
paymentMethodNonce: nonceFromTheClient,
// 可設定不同的 merchantAccountId( for 不同的貨幣)
merchantAccountId: process.env.BRAINTREE_MERCHANT_ACCOUNT_ID,
options: {
submitForSettlement: true,
},
},
(error, result) => {
if (error) {
res.status(500).json(error);
} else {
res.json(result);
}
}
);
};
set paypal
Processing –> paypal –> set PayPal Email, PayPal Client Id, PayPal Client Secret –> Link PayPal Sandbox
![pic8](/2021/12/07/js-5/pic8.png)
![pic9](/2021/12/07/js-5/pic9.png)
add paypal example code
1 | function showDropIn() { |
PayPal sandbox(需先申請正式 paypal帳號)
get paypal merchant account
My Apps & Credentials –> Create App –> get payapl merchant account information
![pic11](/2021/12/07/js-5/pic11.png)
![pic12](/2021/12/07/js-5/pic12.png)
![pic16](/2021/12/07/js-5/pic16.png)
get paypal personal account
SANDBOX –> Accounts –> Create account –> get pernal account information
![pic13](/2021/12/07/js-5/pic13.png)
![pic14](/2021/12/07/js-5/pic14.png)
![pic15](/2021/12/07/js-5/pic15.png)
Test Credit Card Account Numbers
Type | account #1 | account #2 |
---|---|---|
American Express | 378282246310005 | 371449635398431 |
JCB | 3530111333300000 | 3566002020360505 |
Visa | 4111111111111111 | 4012888888881881 |
MasterCard | 5555555555554444 | 5105105105105100 |