|
| 1 | +require_relative 'lib/tapsilat' |
| 2 | +require 'dotenv/load' |
| 3 | + |
| 4 | +# Configure Tapsilat |
| 5 | +Tapsilat.configure do |config| |
| 6 | + config.base_url = ENV['TAPSILAT_BASE_URL'] || 'https://panel.tapsilat.dev/api/v1' |
| 7 | + config.api_token = ENV['TAPSILAT_API_KEY'] |
| 8 | +end |
| 9 | + |
| 10 | +client = Tapsilat::Client.new |
| 11 | + |
| 12 | +puts "=== Tapsilat Ruby SDK Example (Modern Architecture) ===" |
| 13 | + |
| 14 | +begin |
| 15 | + # 1. Organization Settings |
| 16 | + settings = client.organization.settings |
| 17 | + puts "✅ Organization Settings: #{settings['organization_name']}" |
| 18 | + |
| 19 | + # 2. Build and Create Order |
| 20 | + buyer = Tapsilat::BuyerDTO.new( |
| 21 | + name: 'Ruby', |
| 22 | + surname: 'Tester', |
| 23 | + email: 'ruby.tester@example.com', |
| 24 | + gsm_number: '+905001234567', |
| 25 | + identity_number: '11111111111' |
| 26 | + ) |
| 27 | + |
| 28 | + order_req = client.orders.build_order( |
| 29 | + amount: 100.0, |
| 30 | + currency: 'TRY', |
| 31 | + locale: 'tr', |
| 32 | + buyer: buyer, |
| 33 | + conversation_id: "RUBY_EXAMPLE_#{Time.now.to_i}" |
| 34 | + ) |
| 35 | + |
| 36 | + # Add basket items |
| 37 | + order_req.basket_items = [ |
| 38 | + Tapsilat::BasketItemDTO.new(id: 'P1', name: 'Premium Service', price: 100.0, quantity: 1, item_type: 'VIRTUAL') |
| 39 | + ] |
| 40 | + |
| 41 | + order_res = client.orders.create(order_req) |
| 42 | + puts "✅ Order Created: #{order_res.reference_id}" |
| 43 | + puts "🔗 Checkout URL: #{order_res.checkout_url}" |
| 44 | + |
| 45 | + # 3. List Subscriptions |
| 46 | + subs = client.subscriptions.list(per_page: 5) |
| 47 | + puts "✅ Subscriptions listed. Count: #{subs['rows']&.size || 0}" |
| 48 | + |
| 49 | +rescue => e |
| 50 | + puts "❌ Example failed: #{e.message}" |
| 51 | + puts e.backtrace.first(5) |
| 52 | +end |
0 commit comments