From b71f367f93e3f112f33174a4c22fac8f9b9d975e Mon Sep 17 00:00:00 2001 From: ken1flan Date: Mon, 17 Oct 2022 07:45:40 +0900 Subject: [PATCH] =?UTF-8?q?Paypal=E6=B1=BA=E6=B8=88=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...n_paypal_gets_data_about_a_transaction.yml | 35 ++++++++++ ...n_paypal_gets_data_about_a_transaction.yml | 67 +++++++++++++++++++ lib/gmo/shop_api.rb | 20 ++++++ spec/gmo/shop_api_spec.rb | 46 +++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_paypal_gets_data_about_a_transaction.yml create mode 100644 fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_paypal_gets_data_about_a_transaction.yml diff --git a/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_paypal_gets_data_about_a_transaction.yml b/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_paypal_gets_data_about_a_transaction.yml new file mode 100644 index 0000000..43a58ec --- /dev/null +++ b/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_paypal_gets_data_about_a_transaction.yml @@ -0,0 +1,35 @@ +--- +http_interactions: +- request: + method: post + uri: https:///payment/EntryTranPaypal.idPass + body: + encoding: UTF-8 + string: OrderID=1665961543&JobCd=CAPTURE&Amount=100&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Sun, 16 Oct 2022 23:05:43 GMT + Content-Type: + - text/plain;charset=Windows-31J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: OrderID=1665961543&AccessID=37dc5228bcca9474fbe7cc4c911e898b&AccessPass=f59990590602293bd9b1aefdde90bf8c + recorded_at: Sun, 16 Oct 2022 23:05:43 GMT +recorded_with: VCR 6.0.0 diff --git a/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_paypal_gets_data_about_a_transaction.yml b/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_paypal_gets_data_about_a_transaction.yml new file mode 100644 index 0000000..579ee2a --- /dev/null +++ b/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_paypal_gets_data_about_a_transaction.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: https:///payment/EntryTranPaypal.idPass + body: + encoding: UTF-8 + string: OrderID=1666049036&JobCd=CAPTURE&Amount=100&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 17 Oct 2022 23:23:57 GMT + Content-Type: + - text/plain;charset=Windows-31J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: OrderID=1666049036&AccessID=0c3ce8ac4d8578942bdc2fb0bbee7657&AccessPass=cbc4fa24f0061c779f4f60a214785c5f + recorded_at: Mon, 17 Oct 2022 23:23:57 GMT +- request: + method: post + uri: https:///payment/ExecTranPaypal.idPass + body: + encoding: UTF-8 + string: OrderID=1666049036&AccessID=0c3ce8ac4d8578942bdc2fb0bbee7657&AccessPass=cbc4fa24f0061c779f4f60a214785c5f&RedirectURL=https%3A%2F%2Fexample.com%2Fpath%2Fto%2Fredirect&ItemName=%8Dw%93%FC%82%B7%82%E9%8F%A4%95i%96%BC&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 17 Oct 2022 23:23:57 GMT + Content-Type: + - text/plain;charset=Windows-31J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: OrderID=1666049036 + recorded_at: Mon, 17 Oct 2022 23:23:57 GMT +recorded_with: VCR 6.0.0 diff --git a/lib/gmo/shop_api.rb b/lib/gmo/shop_api.rb index a7bafa0..337d52c 100644 --- a/lib/gmo/shop_api.rb +++ b/lib/gmo/shop_api.rb @@ -73,6 +73,16 @@ def entry_tran_pay_easy(options = {}) post_request name, options end + # 【PayPal決済】 + # 取引登録 + # これ以降の決済取引で必要となる取引IDと取引パスワードの発行を行い、取引を開始します。 + def entry_tran_paypal(options = {}) + name = "EntryTranPaypal.idPass" + required = [:order_id, :job_cd, :amount] + assert_required_options(required, options) + post_request name, options + end + # 【LINE Pay決済】 # 20.1.2.1. 取引登録 # これ以降の決済取引で必要となる取引IDと取引パスワードの発行を行い、取引を開始します。 @@ -322,6 +332,16 @@ def exec_tran_pay_easy(options = {}) post_request name, options end + # 【PayPal決済】 + # 決済実行 + # PayPalと通信を行い決済要求結果を返します。 + def exec_tran_paypal(options = {}) + name = "ExecTranPaypal.idPass" + required = [:access_id, :access_pass, :order_id, :item_name, :redirect_url] + assert_required_options(required, options) + post_request name, options + end + # 【LINE Pay決済】 # 20.1.2.2. 決済実行 def exec_tran_linepay(options = {}) diff --git a/spec/gmo/shop_api_spec.rb b/spec/gmo/shop_api_spec.rb index ab6066c..170686d 100644 --- a/spec/gmo/shop_api_spec.rb +++ b/spec/gmo/shop_api_spec.rb @@ -98,6 +98,25 @@ end end + describe "#entry_tran_paypal" do + it "gets data about a transaction", :vcr do + order_id = @order_id + result = @service.entry_tran_paypal({ + :order_id => order_id, + :job_cd => 'CAPTURE', + :amount => 100 + }) + result["AccessID"].nil?.should_not be_truthy + result["AccessPass"].nil?.should_not be_truthy + end + + it "got error if missing options", :vcr do + lambda { + result = @service.entry_tran_paypal() + }.should raise_error("Required order_id, job_cd, amount were not provided.") + end + end + describe "#entry_tran_linepay" do it "gets data about a transaction", :vcr do order_id = @order_id @@ -429,6 +448,33 @@ end end + describe "#exec_tran_paypal" do + it "gets data about a transaction", :vcr do + order_id = generate_id + result = @service.entry_tran_paypal({ + :order_id => order_id, + :job_cd => 'CAPTURE', + :amount => 100 + }) + access_id = result["AccessID"] + access_pass = result["AccessPass"] + result = @service.exec_tran_paypal({ + :order_id => order_id, + :access_id => access_id, + :access_pass => access_pass, + :redirect_url => 'https://example.com/path/to/redirect', + :item_name => '購入する商品名' + }) + result["OrderID"].nil?.should_not be_truthy + end + + it "got error if missing options", :vcr do + lambda { + result = @service.exec_tran_paypal() + }.should raise_error("Required access_id, access_pass, order_id, item_name, redirect_url were not provided.") + end + end + describe "#exec_tran_linepay" do it "gets data about a transaction", :vcr do order_id = generate_id