payify 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +80 -18
- data/lib/payify/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ae7f58afc3e60048eb7fd0805544c7ba63998c515eb27ee32596d5a655a093
|
4
|
+
data.tar.gz: 54d8895cfb775340d9e4a582bb5129ec13597cd755fc055f063067a7c5fd3755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69995924741921bd60e5687bdc45093267ae5269530e24a3d63219de930819d0f810066edfedb2f5a76bfeb81b0c6405bb563a04f236fa09cd36bd5543136996
|
7
|
+
data.tar.gz: 78ca6aebe7be93be3cb78732710d0ebd09b4ba4edf1340663b2de9873dc5263c8807d65d12466a44bf3e354785de8e197c6694faebd17863fa0ab18d879956a8
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Payify
|
2
2
|
|
3
|
+
<span>[](https://rubygems.org/gems/payify)</span> <span>
|
4
|
+
[](https://github.com/andrewdsilva/payify)</span> <span>
|
5
|
+
</span> <span>
|
6
|
+
[](http://opensource.org/licenses/MIT)</span> <span>
|
7
|
+
</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
|

|
@@ -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.1.
|
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-
|
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.
|
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: []
|