Ruby ์ฌ์ฉ์๋ฅผ ์ํ ํ์ดํ REST API ์ฐ๋ ๋ชจ๋์ ๋๋ค.
Add this line to your application's Gemfile:
gem 'httparty'
gem 'payple', git: 'https://github.com/Karoid/payple-rest-client-ruby'
And then execute:
$ bundle install
Payple.cpay.configure do |config|
config.cst_id = 'test'
config.cust_key = 'abcd1234567890'
config.refund_key = 'a41ce010ede9fcbfb3be86b24858806596a9db68b79d138b147c3e563e1829a0'
config.referer = 'http://localhost:3000'
config.is_test_mode = true
end
๋ง์ฝ ํ ์คํธ ์ํ๋ผ๋ฉด is_test_mode ๊ฐ์ true๋ก ์ค์ ํ๋ค. referer์ ์๋น์ค URL์ ๋ฃ์ด์ผ ํ๋ค
Rails ๊ธฐ์ค
# Controller ์ก์
์์ฑ
def payple_auth
render json: Payple.cpay.auth_raw
end
์ผ๋ฐ ๊ฒฐ์ ์ผ ๊ฒฝ์ฐ
Payple.cpay.cert_confirm(cert_url: "๋ฐํ๋ฐ์ PCD_PAY_COFURL", auth_key: "๋ฐํ๋ฐ์ PCD_AUTH_KEY", request_key: "๋ฐํ๋ฐ์ PCD_PAY_REQKEY๊ฐ")
์ ๊ธฐ ๊ฒฐ์ ์ผ ๊ฒฝ์ฐ
Payple.cpay.cert_confirm(cert_url: "๋ฐํ๋ฐ์ PCD_PAY_COFURL", auth_key: "๋ฐํ๋ฐ์ PCD_AUTH_KEY", request_key: "๋ฐํ๋ฐ์ PCD_PAY_REQKEY๊ฐ", payer_id: "์นด๋๋ฑ๋ก ํ ๋ฆฌํด๋ฐ์ ๋น๋งํค(PCD_PAYER_ID)")
Payple.cpay.refund(oid: "ํ๋ถํ oid", pay_date: "YYYYMMDD ํ์์ ๊ฒฐ์ ์ผ์ ํน์ ruby Date, Time, DateTime ํ์", refund_total: "ํ๋ถํ ๊ธ์ก. ์ด ๊ธ์ก๋ณด๋ค ์์ผ๋ฉด ๋ถ๋ถํ๋ถ๋จ")
๋ฐฐ์ด์ ์ฒซ๋ฒ์งธ ์์๋ก ๋ค์ ๊ฒฐ์ url, ๋๋ฒ์งธ ์์๋ก ์ธ์ฆ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๊ฐ ์ถ๋ ฅ๋๋ค.
Payple.cpay.auth
=> [
"https://democpay.payple.kr/index.php?ACT_=PAYM&CPAYVER=202102051731",
{
:PCD_CST_ID=>"N2hQWnYrZFpYc1crYnpiR1dTMzdzQT09",
:PCD_CUST_KEY=>"V3lNUzNXNU4wNW1uZlFMejFGdktyQT09",
:PCD_AUTH_KEY=>"K0VnWlZ5TWZSaGNla1Vpay96YnNQQTFnYXcyVWxlSzJGTHdtNHpNTndIUmJIZ2IrUFI1VExnZzhvOGNqS2MwR0RXL2ZVVjNXbUNBSG43ajdJNXJlelZuKzBXenZNa2RQSGMwdzJlNndBS3dwMTF4Y29OMkdEaFI4RjZSQVpidVpkNkprbkcwalF0L05xaVFOSXk4WWZqUVg2YUJNSnJiTEFwT05WOXhzSWRaRGFWN1NxeitkTkdWeDFjV2l6dVVRakZ0MVVGWTA0ZW9rZWlvbE0xNmZHRGlyczNrWEtTUkhxakpoWDhqWTFxUUF4N1pseW05QTVFbGY5VUs4WExHRDRubEs4Z3JiOTFNS2djKzZLUDN2RVE9PQ=="
}
]
ํ์ดํ ๊ณต์ ๋ฌธ์์์ cst_id, custKey๋ฅผ ์ ์ธํ ํ๋ผ๋ฏธํฐ๋ฅผ ํจ์์ ์ธ์๋ก ๋๊ธฐ๋ฉด ์ํ๋ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋๋ค.
๋ค์์ ์ ๊ธฐ๊ฒฐ์ ๊ฐ๋งน์ ์ธ์ฆ ์์ฒญ ์์์ฝ๋์ด๋ค.
๋ฐฐ์ด์ ์ฒซ๋ฒ์งธ ์์๋ก ๋ค์ ๊ฒฐ์ url, ๋๋ฒ์งธ ์์๋ก ์ธ์ฆ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๊ฐ ์ถ๋ ฅ๋๋ค.
Payple.cpay.auth({PCD_PAYCHK_FLAG: "Y"})
=> [
"https://democpay.payple.kr/php/PayChkAct.php",
{
:PCD_CST_ID=>"N2hQWnYrZFpYc1crYnpiR1dTMzdzQT09",
:PCD_CUST_KEY=>"V3lNUzNXNU4wNW1uZlFMejFGdktyQT09",
:PCD_AUTH_KEY=>"K0VnWlZ5TWZSaGNla1Vpay96YnNQQTFnYXcyVWxlSzJGTHdtNHpNTndIUmJIZ2IrUFI1VExnZzhvOGNqS2MwR0RXL2ZVVjNXbUNBSG43ajdJNXJlelZuKzBXenZNa2RQSGMwdzJlNndBS3dwMTF4Y29OMkdEaFI4RjZSQVpidVpkNkprbkcwalF0L05xaVFOSXk4WWZqUVg2YUJNSnJiTEFwT05WOXhzSWRaRGFWN1NxeitkTkdWeDFjV2l6dVVRakZ0MVVGWTA0ZW9rZWlvbE0xNmZHRGlyczNrWEtTUkhxakpoWDhqWTFxUUF4N1pseW05QTVFbGY5VUs4WExHRDRubEs4Z3JiOTFNS2djKzZLUDN2RVE9PQ=="
}
]
Payple.cpay.payment(
pay_type: :transfer,
oid: 'test201804000001',
pay_date: '20200320'
)
๋ฑ๋ก ์นด๋ ์กฐํ
Payple.cpay.payer(payer_id: "PCD_PAYER_ID ๊ฐ").parsed_response
=> {"PCD_PAY_RST"=>"success", "PCD_PAY_CODE"=>"0000", "PCD_PAY_MSG"=>"ํ์์กฐํ ์ฑ๊ณต", "PCD_PAY_TYPE"=>"card", "PCD_PAY_BANKACCTYPE"=>"๊ฐ์ธ", "PCD_PAYER_ID"=>"cVpMejdJVDliM0FrK3U5b3AyY2hOZz09", "...
๋ฑ๋ก ์นด๋ ์ญ์
Payple.cpay.delete_payer(payer_id: "PCD_PAYER_ID ๊ฐ").parsed_response
=> {"PCD_PAY_RST"=>"success", "PCD_PAY_CODE"=>"0000", "PCD_PAY_MSG"=>"ํ์์กฐํ ์ฑ๊ณต", "PCD_PAY_TYPE"=>"card", "PCD_PAY_BANKACCTYPE"=>"๊ฐ์ธ", "PCD_PAYER_ID"=>"cVpMejdJVDliM0FrK3U5b3AyY2hOZz09", "...
์ ์๋ ๊ฒฐ์ ๋ฐฉ์ง๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ
pay_month, pay_year๋ฅผ ์
๋ ฅํ๋ค.
Payple.cpay.payment_again(pay_type: 'card', payer_id: 'PCD_PAYER_ID ๊ฐ', goods_name: '์ฌ๊ฒฐ์ ํ๋ ์ํ๋ช
', pay_total: '๊ฒฐ์ ํ๋ ์ํ ๊ธ์ก', pay_year: 2021, pay_month: 01).parsed_response
=> {"PCD_PAY_RST"=>"success", "PCD_PAY_CODE"=>"0000", "PCD_PAY_MSG"=>"ํ์์กฐํ ์ฑ๊ณต", "PCD_PAY_TYPE"=>"card", "PCD_PAY_BANKACCTYPE"=>"๊ฐ์ธ", "PCD_PAYER_ID"=>"cVpMejdJVDliM0FrK3U5b3AyY2hOZz09", "...
์ ์๋ ๊ฒฐ์ ๋ฐฉ์ง๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ
pay_month, pay_year๋ฅผ ์
๋ ฅํ์ง ์๋๋ค.
Payple.cpay.payment_again(pay_type: 'card', payer_id: 'PCD_PAYER_ID ๊ฐ', goods_name: '์ฌ๊ฒฐ์ ํ๋ ์ํ๋ช
', pay_total: '๊ฒฐ์ ํ๋ ์ํ ๊ธ์ก').parsed_response
ํ์ดํ ๊ณต์ ๋ฌธ์์์ ํ์๊ฐ ์๋ ํ๋ผ๋ฏธํฐ๋ ๋ฌธ์์ ์ ํ ํค ๊ฐ์ ํจ์์ ์ธ์๋ก ๋๊ธฐ๋ฉด ์ํ๋ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋๋ค.
๋ค์์ CERT ์น์ธํ๊ธฐ์ ์์์ด๋ค.
Payple.cpay.cert_confirm(cert_url: "๋ฐํ๋ฐ์ PCD_PAY_COFURL", auth_key: "๋ฐํ๋ฐ์ PCD_AUTH_KEY", PCD_PAY_REQKEY: "๋ฐํ๋ฐ์ PCD_PAY_REQKEY๊ฐ")
์ด๋ฐ์์ผ๋ก ํ์ดํ ๊ณต์ ๋ฌธ์์๋ ๋์์๊ณ ์ด๊ณณ์๋ ์ค๋ช ์ด ์๋ ์์ฒญ๋ณ์๋ ๊ทธ๋ฅ ๋ฌธ์์ ์ ํ ์์ฒญ๋ณ์๋ฅผ ํค๋ก ์ค์ ํ์ฌ ๊ฐ์ ๋๊ธธ ์ ์๋ค. ๋ค๋ง ํ์ ๋ณ์๋ ์ด ๋ฌธ์์ ์ ํ๋๋ก ๊ฐ์ ๋๊ฒจ์ผ GEM์ด ์ ๋๋ก ์๋ํ๋ค.
Payple.gpay.configure do |config|
config.service_id = 'demo'
config.service_key = 'abcd1234567890'
config.referer = 'http://localhost:3000'
config.is_test_mode = true
end
๋ง์ฝ ํ ์คํธ ์ํ๋ผ๋ฉด is_test_mode ๊ฐ์ true๋ก ์ค์ ํ๋ค. referer์ ์๋น์ค URL์ ๋ฃ์ด์ผ ํ๋ค
Rails ๊ธฐ์ค
# Controller ์ก์
์์ฑ
def payple_auth
render json: Payple.gpay.auth
end
access_token๊ณผ expires_in ์ ๋ฐฐ์ด์ ์๋ตํ๋ค.
Payple.gpay.payment(service_oid: "๋ฐํ๋ฐ์ service_oid")
๋๋
Payple.gpay.payment(pay_id: "๋ฐํ๋ฐ์ pay_id")
Payple.gpay.refund(service_oid: "๋ฐํ๋ฐ์ service_oid", totalAmount: "ํ๋ถํ ๊ธ์ก", currency: "USD or KRW", resultUrl: '์๋ต ๋ฐ์ ๋ ์ฌ์ฉํ resultUrl(์ ํ)')
๋๋
Payple.gpay.refund(pay_id: "๋ฐํ๋ฐ์ pay_id", totalAmount: "ํ๋ถํ ๊ธ์ก", currency: "USD or KRW", resultUrl: '์๋ต ๋ฐ์ ๋ ์ฌ์ฉํ resultUrl(์ ํ)')
Payple.gpay.refund(service_oid: "๊ธฐ์กด์ ์ ์ฅํ๋ service_oid", comments: '์ํ๋ช
', totalAmount: "ํ๋ถํ ๊ธ์ก", currency: "USD or KRW", resultUrl: '์๋ต ๋ฐ์ ๋ ์ฌ์ฉํ resultUrl(์ ํ)')
๋๋
Payple.gpay.refund(billing_key: "๊ธฐ์กด์ ์ ์ฅํ๋ billing_key", comments: '์ํ๋ช
', totalAmount: "ํ๋ถํ ๊ธ์ก", currency: "USD or KRW", resultUrl: '์๋ต ๋ฐ์ ๋ ์ฌ์ฉํ resultUrl(์ ํ)')
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
๋ค์ ๋จ๊ณ๋ฅผ ๋ฐ๋ผ๊ฐ๋ฉด Vscode์ ThunderClient ํ์ฅ ํ๋ก๊ทธ๋จ์ผ๋ก ํ์ดํ API๋ฅผ ์ง์ ํ ์คํธํด๋ณผ ์ ์์ต๋๋ค.
.vscode/defaultSettings.json
๋ฅผ.vscode/settings.json
์ผ๋ก ๋ณต์ ํฉ๋๋ค- vscode์์
rangav.vscode-thunder-client
ํ์ฅ ํ๋ฌ๊ทธ์ธ์ ์ค์นํฉ๋๋ค. .vscode/thunder_client/production.env
์๋ ์ค์ฌ์ฉ ํ๊ฒฝ ๋ณ์ ์ค์ ์,.vscode/thunder_client/test.env
์๋ ๊ฐ๋ฐํ๊ฒฝ์ฉ ํ๊ฒฝ ๋ณ์ ์ค์ ์ ๋ค์๊ณผ ๊ฐ์ ํ์์ผ๋ก ์์ฑํฉ๋๋ค
PAYPLE_CST_ID: "example"
PAYPLE_CUST_KEY: "example"
PAYPLE_REFUND_KEY: "example"
PAYPLE_SERVICE_ID: example
PAYPLE_SERVICE_KEY: example
REFERRER: https://www.example.com
- vscode๋ฅผ ์ฌ์์ํ๋ฉด thunder-client ํญ์์ ์ฌ์ ์ ์์ฑ๋ API๋ค์ ํ์ฉํ ์ ์์ต๋๋ค.
Bug reports and pull requests are welcome on GitHub at https://github.com/Karoid/payple-rest-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Payple project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.