payify 0.1.16 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a9d1ca2475c701c3c4c52cf336fe15f4c4af67bd0bda8881f3e46c6138d4e4b
4
- data.tar.gz: 5b860f6d917cdf5d8b5c488ff178b4543fe944abafc2678a373a93af2004e9ea
3
+ metadata.gz: 70ae7f58afc3e60048eb7fd0805544c7ba63998c515eb27ee32596d5a655a093
4
+ data.tar.gz: 54d8895cfb775340d9e4a582bb5129ec13597cd755fc055f063067a7c5fd3755
5
5
  SHA512:
6
- metadata.gz: ad029b4c099016f6d332d1174323f8a7a2dc68e43173690651959d20e80310a8feb8d6794b88149608861035d61f1b9decfc1ebd059a2eca97b4fcff797f3a99
7
- data.tar.gz: 1378445bd65037c4b0593387d25efb9cce4ee738d4546da5f4f8a08105317dbd174deb512b7cb636dc10354df239c072872dd82be4475452548a629512d7c3ff
6
+ metadata.gz: 69995924741921bd60e5687bdc45093267ae5269530e24a3d63219de930819d0f810066edfedb2f5a76bfeb81b0c6405bb563a04f236fa09cd36bd5543136996
7
+ data.tar.gz: 78ca6aebe7be93be3cb78732710d0ebd09b4ba4edf1340663b2de9873dc5263c8807d65d12466a44bf3e354785de8e197c6694faebd17863fa0ab18d879956a8
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Payify
2
2
 
3
+ <span>[![Gem Version](https://img.shields.io/gem/v/payify.svg?label=payify&colorA=D30001&colorB=DF3B3C)](https://rubygems.org/gems/payify)</span> <span>
4
+ [![ruby](https://img.shields.io/badge/ruby-2.6+%20*-ruby.svg?colorA=D30001&colorB=DF3B3C)](https://github.com/andrewdsilva/payify)</span> <span>
5
+ ![Rubocop Status](https://img.shields.io/badge/rubocop-passing-rubocop.svg?colorA=1f7a1f&colorB=2aa22a)</span> <span>
6
+ [![MIT license](https://img.shields.io/badge/license-MIT-mit.svg?colorA=1f7a1f&colorB=2aa22a)](http://opensource.org/licenses/MIT)</span> <span>
7
+ ![Downloads](https://img.shields.io/gem/dt/payify.svg?colorA=004d99&colorB=0073e6)</span>
8
+
3
9
  PayifyRails is a Ruby gem that simplifies payment integration into Ruby on Rails projects. It allows to easily add payment functionality to your models. For example, by applying the HasPaymentConcern to a reservation model, you can manage the payment process for reservations seamlessly.
4
10
 
5
11
  ![Screenshot](./app/assets/images/payify/screenshot.png)
@@ -16,34 +22,44 @@ And then execute:
16
22
 
17
23
  ```
18
24
  bundle install
25
+
26
+ rails payify_engine:install:migrations
19
27
  ```
20
28
 
21
29
  ## Features ✅
22
30
 
23
- - Includes a Payment model
24
- - Provides concerns to easily add a payment system to your model
25
- - Enables payment with Stripe
26
- - Offers a payment form to integrate into your application
27
- - Allows payment status to be checked via an api route
28
- - Allows configuration of payment (currency, VAT)
29
- - Provides a user interface for payment processing
30
- - Enables management of payment status (pending, paid)
31
+ - Easily create a payment using your models (e.g., from a reservation)
32
+ - Set up payment with Stripe in just 2 minutes
33
+ - Add a payment form to an existing page in your application
34
+ - You can configure the currency and tax rates (VAT)
35
+ - You can track the status of your payments (pending, paid)
36
+ - You can check the payment status through the API
31
37
 
32
38
  ## Configuration
33
39
 
34
- For now, Payify uses Stripe as the payment gateway. You can configure the currency using an initializer.
40
+ You can configure the currency using an initializer.
35
41
 
36
42
  ```ruby
37
43
  # initializers/payify.rb
38
44
  Payify.setup do |config|
39
45
  config.currency = "usd"
40
- config.default_tax_rates_id = "eur"
46
+ config.default_tax_rates_id = "txr_1234567890"
41
47
  end
42
48
  ```
43
49
 
50
+ ### Tax rates
51
+
44
52
  To handle VAT or different tax rates on your payments, you need to create tax rates on Stripe and define the default_tax_rates_id or, alternatively, define the tax_rates_id method on your payment-related models. Leave it empty if you don't manage any taxes.
45
53
 
46
- You can set your Stripe API credentials using environment variables. (Secret key, Publishable key)
54
+ To create a tax rate on Stripe, follow these steps:
55
+
56
+ 1. Go to the "Products" menu in your Stripe account.
57
+ 2. Navigate to the "Tax Rates" tab.
58
+ 3. Click on the "New" button located at the top right corner.
59
+
60
+ ### API key
61
+
62
+ You need to set your Stripe API credentials using environment variables. (Secret key, Publishable key)
47
63
 
48
64
  ```ruby
49
65
  # .env
@@ -53,11 +69,13 @@ STRIPE_PUBLISHABLE_KEY="..."
53
69
 
54
70
  ## Usage
55
71
 
72
+ ### Add the functionality to your model
73
+
56
74
  To enable payment functionality for a model, simply include the HasPayment concern:
57
75
 
58
76
  ```ruby
59
77
  class Reservation < ApplicationRecord
60
- include Payify::HasPaymentConcern
78
+ include ::Payify::HasPaymentConcern
61
79
 
62
80
  def amount_to_pay
63
81
  self.price
@@ -70,23 +88,50 @@ class Reservation < ApplicationRecord
70
88
  end
71
89
  ```
72
90
 
91
+ ### Create a payment
92
+
73
93
  When you want to request a payment for a model on which you added the concern, you just need to call the create_payment method.
74
94
 
95
+ Then you can find the id of the new pending payment with payment.id.
96
+
75
97
  ```ruby
76
98
  reservation_1.create_payment
99
+ reservation_1.payment.id # new payment id
77
100
  ```
78
101
 
79
- Then you can find the id of the new pending payment with payment.id.
102
+ You can use the `after_save` event on your model to automatically create the payment. Here's an example of how you can implement it:
80
103
 
81
104
  ```ruby
82
- reservation_1.payment.id
105
+ class Booking < ApplicationRecord
106
+ include ::Payify::HasPaymentConcern
107
+
108
+ after_save :create_payment
109
+
110
+ def amount_to_pay
111
+ total_ttc
112
+ end
113
+ end
83
114
  ```
84
115
 
85
- Now you just have to redirect the user to `/payments/:id/new` or include the payment form in your page.
116
+ ### Include the routes
117
+
118
+ To be able to use the routes of Payify, you need to add the following line to your `config/routes.rb` file:
119
+
120
+ ```ruby
121
+ mount Payify::Engine => '/payify', as: 'payify'
122
+ ```
123
+
124
+ ### Request a payment
125
+
126
+ To allow the user to make a payment, you have two options:
127
+
128
+ 1. Redirect the user to the payment form: You can redirect the user to the payment form using the URL `/payify/payments/:id/new`, where `:id` represents the payment id.
129
+
130
+ 2. Include the payment form on your page:
86
131
 
87
132
  ```ruby
88
133
  # reservation/show.html.erb
89
- <%= render "payify/payments/form", payment: @payment %>
134
+ <%= render "payify/payments/form", payment: @object.payment %>
90
135
  ```
91
136
 
92
137
  After completing the payment process, the user will be redirected to:
@@ -95,6 +140,8 @@ After completing the payment process, the user will be redirected to:
95
140
  /payments/:id/complete
96
141
  ```
97
142
 
143
+ ### Verify the payment
144
+
98
145
  The application will then verify the payment status with Stripe. You can do it manually calling the following method:
99
146
 
100
147
  ```ruby
@@ -119,7 +166,22 @@ To customize the page that displays the payment status, you can create the follo
119
166
  <% end %>
120
167
  ```
121
168
 
122
- ## API
169
+ ### Override the controller
170
+
171
+ If you want to override the `PaymentsController`, create the following file:
172
+
173
+ ```ruby
174
+ # app/controllers/payify/payments_controller.rb
175
+ module Payify
176
+ class PaymentsController < ApplicationController
177
+ include ::Payify::PaymentsControllerConcern
178
+
179
+ ...
180
+ end
181
+ end
182
+ ```
183
+
184
+ ### Using the API
123
185
 
124
186
  If you prefer using the Payify API, after creating the payment object, you can initialize a new Stripe payment by making a request to: `/payments/:id/new.json`
125
187
 
@@ -131,7 +193,7 @@ After making the payment, you can make a request to the following endpoint to up
131
193
  /payments/:id/complete.json
132
194
  ```
133
195
 
134
- ## Status
196
+ ### Status
135
197
 
136
198
  You can access the payment status using `@payment.status`. The possible statuses are:
137
199
 
@@ -1,5 +1,3 @@
1
- <script src="https://js.stripe.com/v3/"></script>
2
-
3
1
  <%= form_with(id: "payment-form", url: payify.complete_payment_path, method: "post") do |form| %>
4
2
  <div id="payment-element">
5
3
  </div>
@@ -11,36 +9,50 @@
11
9
  <% end %>
12
10
 
13
11
  <script>
14
- const stripe = Stripe("<%= Payify.stripe_publishable_key %>");
12
+ function loadStripeAndExecuteCode() {
13
+ if (typeof Stripe === "undefined") {
14
+ var script = document.createElement("script");
15
+ script.src = "https://js.stripe.com/v3/";
16
+ script.onload = function() {
17
+ executeCode();
18
+ };
19
+ document.head.appendChild(script);
20
+ } else {
21
+ executeCode();
22
+ }
23
+ }
24
+
25
+ function executeCode() {
26
+ const stripe = Stripe("<%= Payify.stripe_publishable_key %>");
15
27
 
16
- const options = {
17
- clientSecret: "<%= payment.stripe_client_secret %>",
18
- };
28
+ const options = {
29
+ clientSecret: "<%= payment.stripe_client_secret %>",
30
+ };
19
31
 
20
- const elements = stripe.elements(options);
32
+ const elements = stripe.elements(options);
21
33
 
22
- const paymentElement = elements.create("payment");
23
- paymentElement.mount("#payment-element");
34
+ const paymentElement = elements.create("payment");
35
+ paymentElement.mount("#payment-element");
24
36
 
25
- const form = document.getElementById("payment-form");
37
+ const form = document.getElementById("payment-form");
26
38
 
27
- form.addEventListener("submit", async (event) => {
28
- event.preventDefault();
39
+ form.addEventListener("submit", async (event) => {
40
+ event.preventDefault();
29
41
 
30
- const {error} = await stripe.confirmPayment({
31
- elements,
32
- confirmParams: {
33
- return_url: "<%= request.base_url %>/payify/payments/<%= payment.id %>/complete",
34
- },
42
+ const {error} = await stripe.confirmPayment({
43
+ elements,
44
+ confirmParams: {
45
+ return_url: "<%= request.base_url %>/payify/payments/<%= payment.id %>/complete",
46
+ },
47
+ });
48
+
49
+ if (error) {
50
+ const messageContainer = document.querySelector("#error-message");
51
+ messageContainer.textContent = error.message;
52
+ } else {
53
+ }
35
54
  });
55
+ }
36
56
 
37
- if (error) {
38
- const messageContainer = document.querySelector("#error-message");
39
- messageContainer.textContent = error.message;
40
- } else {
41
- // Your customer will be redirected to your `return_url`. For some payment
42
- // methods like iDEAL, your customer will be redirected to an intermediate
43
- // site first to authorize the payment, then redirected to the `return_url`.
44
- }
45
- });
57
+ loadStripeAndExecuteCode();
46
58
  </script>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Payify
4
- VERSION = "0.1.16"
4
+ VERSION = "0.1.18"
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Lopez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_model_serializers
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.13
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.13
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: dotenv-rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +120,7 @@ homepage: https://github.com/andrewdsilva/payify
106
120
  licenses:
107
121
  - MIT
108
122
  metadata: {}
109
- post_install_message:
123
+ post_install_message:
110
124
  rdoc_options: []
111
125
  require_paths:
112
126
  - lib
@@ -121,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
135
  - !ruby/object:Gem::Version
122
136
  version: '0'
123
137
  requirements: []
124
- rubygems_version: 3.4.14
125
- signing_key:
138
+ rubygems_version: 3.1.6
139
+ signing_key:
126
140
  specification_version: 4
127
141
  summary: Payment integration for Ruby on Rails projects.
128
142
  test_files: []