金流

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

set CVV

Fraud Management –> CVV –> CVV does not match (when provided) (N) –> For Any Transaction

new Merchant Account ID

Business –> new Sandbox Merchant Account –> set Merchant Account ID + currency

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

add paypal example code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function showDropIn() {
return (
<div onBlur={() => setData({ ...data, error: "" })}>
{data.clientToken != null && products.length > 0 ? (
<DropIn
options={{
authorization: data.clientToken,
// ad paypal option
paypal: {
flow: "vault",
},
}}
onInstance={(instance) => (data.instance = instance)}
/>
) : null}
<button onClick={handleBuy} className="btn btn-success btn-block">
Pay
</button>
</div>
);
}

PayPal sandbox(需先申請正式 paypal帳號)

get paypal merchant account

My Apps & Credentials –> Create App –> get payapl merchant account information

get paypal personal account

SANDBOX –> Accounts –> Create account –> get pernal account information

Test Credit Card Account Numbers

Type account #1 account #2
American Express 378282246310005 371449635398431
JCB 3530111333300000 3566002020360505
Visa 4111111111111111 4012888888881881
MasterCard 5555555555554444 5105105105105100

參考資料