Stripe Node JS向客户收费

时间:2018-10-16 04:23:15

标签: javascript node.js stripe-payments

我要做的就是向这样的客户收费:

function battleship() 
{
var guess; //Stores user's guess
var userchoices = []; //records user's guess until ship is sunk or user chickens out
var issunk = false; //status of ship
var hits = 0; //number of hits
var guesses = 0; //number of guesses
var randomloc = Math.floor(Math.random() * 5); //Random Number Generator
var location1 = randomloc; 
var location2 = location1 + 1;
var location3 = location2 + 1;

while(issunk == false)
{
    guess = prompt("Ready,Aim,Fire! (Enter a number 0-6):");
    console.log("users input = " + guess);

    if(guess == null) // If users presses 'OK' without entering anything or the 'Cancel' this would break the loop.
        break;

    if (guess < 0 || guess > 6){
        alert("Please enter a valid cell number. No of guesses has been incremented.");
guesses++; //Gotta punish the player.
    }
    else if (userchoices.includes(guess) == false) /*instead of doing what i did yo u 
can change this line to "else if (userchoices.includes(guess)) and then put the 
following oprations in its else clause. */
    {
        guesses++;
        userchoices[guesses] = guess;
        console.log("User choices = " + userchoices);

        if (guess == location1 || guess == location2 || guess == location3)
        {
            alert("Enemy Battleship HIT");
            hits = hits + 1;
            if (hits == 3)
            {
                issunk = true;
                alert("Enemy battleship sunk");
            }
        }
            else
            {
                alert("You Missed");
            }
    }
         else
        {
            alert("you have already fired at this location.")
        }
    if (issunk) //writing issunk == true is overkill
    {
        var stats = "you took " + guesses + " guesses to sink the battleship. You 
accuracy was " + (3/guesses);
        alert(stats);
    }
}
if(guess == null && issunk == false)
console.log("You failed");  //Humiliate the user for chickening out.
userchoices = []; //Empties the array so user can start over again without relaoding the page
issunk = false; //sets issunk to false for a new game
var randomloc = Math.floor(Math.random() * 5); //creates new random numbers for ship coordinates
}

根据文档:

https://stripe.com/docs/api/charges/create 这应该是可能的, 但是我得到了错误:

var stripe = require("stripe")("sk_test_5uwvjas5uFYUCZN5d3YdAT19");

stripe.charges.create({
  amount: 1000,
 currency: "usd",
 customer: "cus_112121212", // CUSTOMER ID
 destination: {
          account: "{CONNECTED_STRIPE_ACCOUNT_ID}",
      },
}).then(function(charge) {
 // asynchronously called
});

我看错文档了吗?谢谢。

1 个答案:

答案 0 :(得分:0)

查看Firestripe示例,因为它位于Node js中。

https://github.com/firebase/functions-samples/blob/master/stripe/functions/index.js

如果这没有帮助,请确认客户已附加源。如果没有,那么您就无法向该客户收费。