@bigbinary/neeto-payments-frontend
v3.0.25
Published
To manage payments across the neeto products.
Downloads
3,837
Readme
neeto-payments-nano
The neeto-payments-nano
manages payments across neeto products. The nano exports the @bigbinary/neeto-payments-frontend
NPM package and neeto-payments-engine
Rails engine for development.
Contents
Development with Host Application
Engine
The engine is used to manage payments across neeto products.
Installation
Add this line to your application's Gemfile:
source "NEETO_GEM_SERVER_URL" do # ..existing gems gem 'neeto-payments-engine' end
And then execute:
bundle install
Add this line to your application's
config/routes.rb
file:mount NeetoPaymentsEngine::Engine, at: '/payments'
Configure the following environment variables.
APP_URL=#Application URL STRIPE_PUBLISHABLE_KEY='pk_test_fnFiGXjRkMXnLkueiNKJidGU00V83aRC0V' STRIPE_SECRET_KEY='sk_test_eyKnYYoSDcvojBAiFoDv3QJQ00z0yOlt89'
NB: Replace
APP_URL
environment variable value with the host application's base URL without a trailing slash for example:https://app.neetocal.net
. Stripe environment variables values aretest
mode keys.Run the following command to subscribe Stripe webhooks events.
bundle exec rails neeto_payments_engine:stripe:webhooks:subscribe
- After successful subscription, the above command will return the list of events subscribed and the details of environment variable.
- Sample output
*** Successfully subscribed for webhooks *** Please add the following environment variable STRIPE_WEBHOOK_SECRET='whsec_06LHs3IOmLOgEzXDm3otErje8I4Q15ME' ============================================== Subscribed events: [ "account.updated", "payment_intent.payment_failed", "payment_intent.processing", "payment_intent.succeeded", "charge.refund.updated", "charge.refunded" ]
- Add the returned environment variable and its value.
Add the following secret values to
config/secrets.yml
.host: <%= ENV['APP_URL'] || ENV['HEROKU_APP_URL'] %> stripe: publishable_key: <%= ENV['STRIPE_PUBLISHABLE_KEY'] %> secret_key: <%= ENV['STRIPE_SECRET_KEY'] %> webhooks: secret: <%= ENV['STRIPE_WEBHOOK_SECRET'] %>
Add the following line to application's
config/initializer/neeto_payments_engine.rb
file. Replace theholdable_class
value with a model name where you want to associate your Stripe account in the host application.NeetoPaymentsEngine.holdable_class = "Organization"
Add the following association to the model you defined as holdable_class in step 7.
has_one :stripe_integration, class_name: "::NeetoPaymentsEngine::Stripe::Account", foreign_key: :holdable_id
Add the following association to the chargeable model. The chargeable model is the model in the host application which needs to charge for its service. For example
Meeting
model inneetoCal
where meeting service is a chargeable one.has_one :charge, as: :chargeable, class_name: "::NeetoPaymentsEngine::Stripe::Charge", dependent: :destroy
Add the following association to the payable model.
has_one :payment, as: :payable, class_name: "::NeetoPaymentsEngine::Stripe::Transaction", dependent: :destroy
Add the following queue to your sidekiq config file
config/sidekiq.yml
queues: - payment # For neeto-payments-engine
Usage
You can learn more about setup and usage here:
Frontend package
Installation
- Install the latest
neeto-payments-frontend
package using the below command:yarn add @bigbinary/neeto-payments-frontend
neeto-payments-frontend
has a few peer dependencies that are required for the proper functioning of the package. Install all the peer dependencies using the below command:yarn add @bigbinary/[email protected] @bigbinary/[email protected] @bigbinary/[email protected] @bigbinary/[email protected] @bigbinary/[email protected] @honeybadger-io/[email protected] @honeybadger-io/[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
Instructions for development
Check the Frontend package development guide for step-by-step instructions to develop the frontend package.
Components
1. Dashboard
(source code)
Props
holdableId
: To specify the ID of the entity that holds the stripe account. This is an optional prop. If the value is not specified, the current organization ID is taken as the default value while querying for transactions.payableEntityColumns
: To specify the columns from the payable entity which need to be additionally displayed. It is an optional prop that defaults to[]
if not specified.tabs
: To specify the tabs to be displayed in the payments dashboard. It is an optional parameter.headerProps
: To specify the props to be passed to the neetoUIHeader
component used in theDashboard
.
Configuration
- Refer to the Dashboard section for detailed information on the available configurations for the
Dashboard
component.
Usage
import React, { useState } from "react";
import { Dashboard } from "@bigbinary/neeto-payments-frontend";
const App = () => {
const headerProps = {
className: "w-80",
// Your header properties
};
return (
<Dashboard
tabs={["all", "successful"]}
headerProps={headerProps}
/>
);
};
export default App;
2. PaymentKindRestrictionAlert
(source code)
Props
isOpen
: To specify whether the Stripe connect restriction alert should be opened or closed.paymentKind
: To specify the type of Stripe payment kind for rendering related content to alert either as "standard" or "platform". If Stripe Standard is connected the alert shall forbid Stripe Platform connect and vice versa.onClose
: Handler function that is triggered when the disconnect button is clicked.
Usage
import React, { useState } from "react";
import { PaymentKindRestrictionAlert } from "@bigbinary/neeto-payments-frontend";
const App = () => {
const [isStripePlatformConnectedAlertOpen, setIsStripePlatformConnectedAlertOpen] = useState(false);
return (
<PaymentKindRestrictionAlert
isOpen={isStripePlatformConnectedAlertOpen}
paymentKind="standard"
onClose={() => setIsStripePlatformConnectedAlertOpen(false)}
/>
);
};
export default App;
4. PayoutsDashboard
(source code)
Props
payoutsPageRoute
: The route for the payouts page.isPlatformEnabled
: Indicates whether the platform is enabled or not.
Usage
import React from "react";
import { PayoutsDashboard } from "@bigbinary/neeto-payments-frontend";
const App = () => {
return (
<PayoutsDashboard
isPlatformEnabled
payoutsPageRoute={routes.admin.payment.stripePayouts.show}
/>
);
};
export default App;
Hooks
1. useStripePromise
(source code)
- This hook is used to generate the
stripePromise
object to be passed to the stripe<Elements>
context. TheuseStripePromise
hook takes a stripe account identifier as input and returns aPromise
. - Usage in neetoForm.
:memo: Note:
STRIPE_PUBLISHABLE_KEY
environment variable must be present for this hook to work.
Usage
const stripeAccountIdentifier = "acct_1Mtqtz2e5McIywz4";
const stripePromise = useStripePromise(stripeAccountIdentifier);
...
<Elements stripe={stripePromise}>
<CardElement />
</Elements>
Functions
1. buildStripeTransactionLink
(source code)
- This function is used to generate the stripe transaction link from payment identifier.
Parameters
identifier
: The payment identifier.isLive
: Specifying whether or not the environment is live. It defaults totrue
.
Usage
const transactionLink = buildStripeTransactionLink(
"pi_3MqWX92fKivMPpZ11EPmOBBR",
false
);
Instructions for Publishing
Consult the building and releasing packages guide for details on how to publish.