payify 0.1.17 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +80 -18
- data/lib/payify/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3256b950f558c1a65f1a1f1aaaa0746c2f61fd77157ed0595597f813ad44b85
|
4
|
+
data.tar.gz: 79ff6a4cac237777cafa252056beec61fc350c3635792275152b64777fb75548
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd048981b50ef906688ed6c5081aaea402f737963c4faba2660f79d809f2f8e876a8c14a2602606f35a71565ab89c521d7a841783ac19dc88c3ac2830663e79e
|
7
|
+
data.tar.gz: b11df362c1c24b8d5e2714bcd394c7db55bcf7bddd5bf6255666f43256696927763a4a853abb42621d219c25410460db61b97edf8f70a47231ab35403743099e
|
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
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
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
|
-
|
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 = "
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
196
|
+
### Status
|
135
197
|
|
136
198
|
You can access the payment status using `@payment.status`. The possible statuses are:
|
137
199
|
|
data/lib/payify/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Lopez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-22 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
|
@@ -121,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
135
|
- !ruby/object:Gem::Version
|
122
136
|
version: '0'
|
123
137
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
138
|
+
rubygems_version: 3.0.3.1
|
125
139
|
signing_key:
|
126
140
|
specification_version: 4
|
127
141
|
summary: Payment integration for Ruby on Rails projects.
|