Integration with Stripe

What You'll Need

Backbench account - Sign Up, the personal account will always remain free to use.

Stripe Login - Create an account(www.stripe.com) and activate your account.

Prerequisites

  1. Generating api keys: once you signup and activate your account for api keys select developers section from stripe dashboard under that select api keys and there is a toggle switch to view test data to generate your test apis.

Operation 1: Creating checkout for for Payment.

Frontend

  1. Select +, in the upper right corner of file manager to create a html file. For example, say "stripe.html" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace your data key with publishable key from your stripe dashboard under developers.

  4. Select save.

<html>
  <form action="/stripe" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key=<Stripe_Key>
    data-amount="999"
    data-name="Demo Site"
    data-description="Example charge"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto">
  </script>
</form>
</html>

Dependencies

Only for nodejs. Paste following code as package.json.

package.json
{
   "dependencies":{
      "stripe":"4.19.1"
   }
}

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "stripe.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace SECRET KEY from stripe dashboard under developers.

  4. Select save.

var stripe = require("stripe")("SECRET KEY");
module.exports.endpoint = function(req, cb) {
    stripe.charges.create({
        amount: 2000,
        currency: "usd",
        source: "tok_visa", // obtained with Stripe.js
        description: "Charge for mia.johnson@example.com"
    }, function(err, charge) {
        // asynchronously called
        if (err) {
            console.log(err);
            cb(err.message);
        }
        cb(undefined, {
            res: charge
        });
    });
};

Operation 2: Retrieve balance

Balance

This is an object representing your Stripe balance. You can retrieve it to see the balance currently on your Stripe account. You can also retrieve the balance history, which contains a list of transactions that contributed to the balance (charges, pay-outs, and so forth).

Retrieve balance

Retrieves the current account balance, based on the authentication that was used to make the request.

stripe.balance.retrieve(function(err, balance) {
  // asynchronously called
});
Retrieve a balance transaction
Retrieves the balance transaction with the given ID.
stripe.balance.retrieveTransaction(
  "REPLACE TRANSACTION ID",
  function(err, balanceTransaction) {
    // asynchronously called
  }
);

TRANSACTION ID: The ID of the desired balance transaction, as found on any API object that affects the balance.

Operation 3: List all balance history

Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.

stripe.balance.listTransactions({ limit: 3 }, function(err, transactions) {
  // asynchronously called
});

Operation 3: Create a charge

Charges

To charge a credit or a debit card, you create a charge object.

To charge a credit card or other payment source, you create a charge object.

stripe.charges.create({
  amount: amount,
  currency: "currency",
  source: "tok_visa", // obtained with Stripe.js
  description: "Charge for madison.harris@example.com"
}, function(err, charge) {
  // asynchronously called
});

Amount: A positive integer representing how much to charge. Currency: 3-letter ISO code for currency.

Other optional parameters description, receipt_email, source.

Operation 4: Retrieve a charge

Retrieves the details of a charge that has previously been created. Supply the unique charge ID that was returned from your previous request, and Stripe will return the corresponding charge information. The same information is returned when creating or refunding the charge.

stripe.charges.retrieve("ch_1CEvhdDdG7hvTLa0PSdmu4ye", function(err, charge) {
    // asynchronously called
  }
);

Charge: The identifier of the charge to be retrieved.

Operation 5: Customers

Customer objects allow you to perform recurring charges, and to track multiple charges, that are associated with the same customer. The API allows you to create, delete, and update your customers. You can retrieve individual customers as well as a list of all your customers.

Create a customer

Creates a new customer object.

stripe.customers.create({
  description: 'Customer for addison.johnson@example.com',
  source: "tok_visa" // obtained with Stripe.js
}, function(err, customer) {
  // asynchronously called
});

Retrieve a customer

Retrieves the details of an existing customer. You need only supply the unique customer identifier that was returned upon customer creation.

stripe.customers.retrieve("CUSTOMER ID",function(err, customer) {
    // asynchronously called
  }
);

List all customers

Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.

stripe.customers.list({ limit: 3 },
  function(err, customers) {
    // asynchronously called
  }
);

Operation 6: Payouts

A Payout object is created when you receive funds from Stripe, or when you initiate a payout to either a bank account or debit card of a connected Stripe account. You can retrieve individual payouts, as well as list all payouts.

Create a payout

To send funds to your own bank account, you create a new payout object. Your Stripe balance must be able to cover the payout amount, or you’ll receive an “Insufficient Funds” error.

If your API key is in test mode, money won’t actually be sent, though everything else will occur as if in live mode.

stripe.payouts.create({
  amount: AMOUNT,
  currency: "CURRENCY"
}, function(err, payout) {
  // asynchronously called
});

Retrieve a payout

Retrieves the details of an existing payout. Supply the unique payout ID from either a payout creation request or the payout list, and Stripe will return the corresponding payout information.

stripe.payouts.retrieve("PAYOUT",
  function(err, payout) { 
  // asynchronously called
  }
}

Payout: The identifier of the payout to be retrieved.

List all payouts

Returns a list of existing payouts sent to third-party bank accounts or that Stripe has sent you. The payouts are returned in sorted order, with the most recently created payouts appearing first.

stripe.payouts.list({ limit: 3 },
  function(err, payouts) {
    // asynchronously called
  }
);

Operation 7: Refunds

Refunds objects allow you to refund a charge that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally charged.

Create a refund

When you create a new refund, you must specify a charge on which to create it.

Creating a new refund will refund a charge that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally charged.

stripe.refunds.create({ charge:CHARGE"
}, function(err, refund) {
  // asynchronously called
});

Charge: The identifier of the charge to refund.

Retrieve a refund

Retrieves the details of an existing payout. Supply the unique payout ID from either a payout creation request or the payout list, and Stripe will return the corresponding payout information.

Retrieves the details of an existing refund.
stripe.refunds.retrieve("re_1CEuDFDdG7hvTLa0khr26CZa", function(err, refund) {
    // asynchronously called
  }
);

List all refunds

Returns a list of all refunds you’ve previously created. The refunds are returned in sorted order, with the most recent refunds appearing first. For convenience, the 10 most recent refunds are always available by default on the charge object.

stripe.refunds.list({ limit: 3 }, function(err, refunds) {
    // asynchronously called
  }
);

Last updated