I am creating a web application using Ruby on Rails in team development.
Since it is still immature, the description and code may be difficult to understand. We will update and brush up the items and changes that could not be described.
If you are a beginner like me, you tend to lose track of
" what you want to look up now " when you search repeatedly, so I will explain technical terms and katakana terms each time.
The customer's credit card information is not saved in the database on the application side, but is saved in PAY.JP. By associating the customer with the credit card and processing it, it becomes an API that allows you to make a secure credit card payment.
In the development of the flea market app, we have implemented the product purchase function using this PAY.JP to make payments with a credit card.
API： An abbreviation for "Application Programming Interface", which means "a program that specializes in one function can be shared" or "a mechanism for sharing software functions".
PAY.JP account creation
Create an account on the PAY.JP site. (Advance preparation)
Write the following in the Gemfile and execute ** bundle install **.
Environment variables: The OS permanently saves the setting values so that they can be set and referenced by the user or the program to be executed. Some can be explicitly created or changed by the user's operation. If you are not sure, you can understand it by executing the ** printenv ** command (check if the environment variables are set) in the terminal.
Since it is not good for security reasons to directly attach the private key or public key to the code, Write the code like this and write it in .bash_profile. Payjp.api_key = ENV['PAYJP_PRIVATE_KEY']
.bash_profile： ** Once at login ** Executed. For example, it is loaded when you start Terminal.app. It is good to set environment variables as to what to set specifically in this file.
.bashrc： ** Executed once when the shell is started **. Hitting bash on the command line will load .bashrc again. (.bash_profile is not read) If you want to set it every time you start the shell, put the setting in this file.
First, check the existence of .bash_profile.
$ ls -a
It wasn't my case. Create an empty file with the ** touch ** command.
$ touch ~/.bash_profile $ touch ~/.bashrc
Confirm that the file is created. (If it is not displayed, execute the following command as it is)
$ ls -a //Example .bash_profile .gitignore Gemfile Rakefile config .bashrc public .ruby-version Gemfile.lock app
$ vim ~/.bash_profile
Described in .bash_profile.
//First, press "i" to enter insert mode. export PAYJP_ACCESS_KEY='sk_test_*************' export PAYJP_PUBLIC_KEY='pk_test_*************' //esc key=> :In the order of wq.bash_Exit profile
When you write the environment variable at the end, be sure to enable the setting with the following command.
$ source ~/.bash_profile
That is all for the introduction of PAY.JP. There are various articles on the implementation of the credit card registration function, so please refer to each one.
[Implementing the purchase function using Payjp in Rails] (https://qiita.com/suzy1031/items/7964829086eb929471a6) [Implementing credit card registration and deletion function with Payjp (Rails)] (https://qiita.com/takachan_coding/items/f7e70794b9ca03b559dd) [[Rails] Implement payment function using payjp ① ~ Credit card registration ~] (https://qiita.com/dice9494/items/4aa04da1056d1f15919e) [Summary of .bash_profile and .bashrc] (https://qiita.com/takutoki/items/021b804b9957fe65e093)