paypal_marketplace 0.0.0 → 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paypal_marketplace.rb +100 -2
  3. metadata +8 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01fcf6e336490d9de201a9133c064f7cec3dbe3bb56f7162e9c775a9a527df6c
4
- data.tar.gz: 7c36cd54f3189b8a6b216869a0389534501635d74eae71c368a948db1ab46b42
3
+ metadata.gz: 3e93e6f13c51680b605f191c7155ce4dd7419fc88e035516c1a36edeb97f1081
4
+ data.tar.gz: 9b5ed9f81630ee5557a8be0ac849c865d773da47813455612f9627ecca095e3c
5
5
  SHA512:
6
- metadata.gz: 2c12f847169aa265370b50c31665de1ed02f7eb025451bc36cbd3fd27130f4994e6c610a08ac51cb42ab1c80f28569b962ddc5f4fa8d88a5574a12c349a9e6b9
7
- data.tar.gz: 99826149319cda59e4a2a20659bb98978af9c33cffa76144aebab3d6cd2883c71a749e79c3a51f8fa91592f28b2668b832e12a3e9974e7def7708904b246c1e6
6
+ metadata.gz: 36cdbe8f713f650e2b4d6ffd6461f2b72ba6e45f3d35ff2e142f4a7971b68a34b3950370942a2ebc8404cffa8425f1435512ad2b0208f69a29072f324ca73019
7
+ data.tar.gz: 25302e910b07f929dbdeb151305483192ed4d0e003b8cecc25ef2d3e0a440b930004c16e4f103622b5a1d43fe0c0c4e74d1241b02ea8c8d9a3f427c6c6ff560a
@@ -1,5 +1,103 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
1
4
  class PaypalMarketplace
2
- def hello
3
- puts "Hello World"
5
+ class << self
6
+ attr_accessor :access_token, :credentials, :development
7
+
8
+ def create_onboarding_link(tracking_id: nil)
9
+ uri = URI(partner_referral_url)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true
12
+
13
+ request = Net::HTTP::Post.new(uri.path, onboarding_headers)
14
+ request.body = onboarding_data(tracking_id: tracking_id).to_json
15
+
16
+ response = http.request(request)
17
+ end
18
+ private
19
+ def onboarding_data(**args)
20
+ {
21
+ tracking_id: args[:tracking_id],
22
+ operations: [{
23
+ operation: "API_INTEGRATION",
24
+ api_integration_preference: {
25
+ rest_api_integration: {
26
+ integration_method: "PAYPAL",
27
+ integration_type: "THIRD_PARTY",
28
+ third_party_details: {
29
+ features: [
30
+ "PAYMENT",
31
+ "REFUND"
32
+ ]
33
+ }
34
+ }
35
+ }
36
+ }],
37
+ products: [
38
+ "EXPRESS_CHECKOUT"
39
+ ],
40
+ legal_consents: [{
41
+ "type": "SHARE_DATA_CONSENT",
42
+ "granted": true
43
+ }]
44
+ }
45
+ end
46
+
47
+ def oauth_headers
48
+ {
49
+ 'Content-Type': 'x-www-form-urlencoded'
50
+ }
51
+ end
52
+
53
+ def onboarding_headers
54
+ {
55
+ 'Content-Type': 'application/json',
56
+ 'Authorization': "Bearer #{access_token}",
57
+ }
58
+ end
59
+
60
+ def partner_referral_url
61
+ "#{base_url_v2}/customer/partner-referrals"
62
+ end
63
+
64
+ def oauth_url
65
+ "#{base_url_v1}/oauth2/token"
66
+ end
67
+
68
+ def get_access_token
69
+ uri = URI(oauth_url)
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ http.use_ssl = true
72
+
73
+ request = Net::HTTP::Post.new(uri.path, oauth_headers)
74
+ request.basic_auth(credentials[:client_id], credentials[:client_secret])
75
+ request.set_form_data({ grant_type: "client_credentials" })
76
+
77
+ response = http.request(request)
78
+
79
+ if response.kind_of? Net::HTTPSuccess
80
+ response_json = JSON.parse(response.body)
81
+ @access_token = response_json["access_token"]
82
+ else
83
+ raise Exception.new('The request for oauth token failed for some reason')
84
+ end
85
+ end
86
+
87
+ def base_url_v1
88
+ if development == true
89
+ "https://api-m.sandbox.paypal.com/v1"
90
+ else
91
+ "https://api-m.paypal.com/v1"
92
+ end
93
+ end
94
+
95
+ def base_url_v2
96
+ if development == true
97
+ "https://api-m.sandbox.paypal.com/v2"
98
+ else
99
+ "https://api-m.paypal.com/v2"
100
+ end
101
+ end
4
102
  end
5
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal_marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indigo Tech Tutorials
@@ -9,9 +9,10 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: This is a ruby API wrapper for the Paypal marketplace API with the partners
13
- API. This allows you to onboard users similar to Stripe connect and allow them to
14
- sell products on your platform and get payed via Paypal
12
+ description: This is a ruby API wrapper for the Paypal marketplace API creating an
13
+ onboarding link via the Paypal Partner Referrals API. This allows you to onboard
14
+ users similar to Stripe connect and allow them to sell products on your platform
15
+ and get payed via Paypal
15
16
  email: indigotechtutorials@gmail.com
16
17
  executables: []
17
18
  extensions: []
@@ -21,7 +22,8 @@ files:
21
22
  homepage: https://rubygems.org/gems/paypal_marketplace
22
23
  licenses:
23
24
  - MIT
24
- metadata: {}
25
+ metadata:
26
+ source_code_uri: https://github.com/indigotechtutorials/paypal-marketplace-ruby
25
27
  rdoc_options: []
26
28
  require_paths:
27
29
  - lib
@@ -38,5 +40,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
40
  requirements: []
39
41
  rubygems_version: 3.6.9
40
42
  specification_version: 4
41
- summary: Ruby API wrapper for paypal marketplace with partners API
43
+ summary: Ruby API wrapper for Paypal marketplace API
42
44
  test_files: []