Skip to content

Commit

Permalink
Merge pull request #5 from l0ck3/master
Browse files Browse the repository at this point in the history
Adds code samples for the API Reference
  • Loading branch information
l0ck3 committed Mar 3, 2015
2 parents 0148032 + 0043f09 commit 405b9c7
Show file tree
Hide file tree
Showing 60 changed files with 249 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*.a
mkmf.log
spec/cassettes

.DS_Store
1 change: 1 addition & 0 deletions samples/authentication/authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill.api_key = "<YOUR_PRIVATE_KEY>"
4 changes: 4 additions & 0 deletions samples/clients/create_new_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Paymill::Client.create(
email: 'lovely-client@example.com',
description: 'Lovely Client'
)
1 change: 1 addition & 0 deletions samples/clients/export_clients_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/clients/get_client_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Client.find('client_88a388d9dd48f86c3136')
1 change: 1 addition & 0 deletions samples/clients/list_clients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Client.all
2 changes: 2 additions & 0 deletions samples/clients/remove_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
client = Paymill::Client.find('client_88a388d9dd48f86c3136')
client.delete
4 changes: 4 additions & 0 deletions samples/clients/update_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
client = Paymill::Client.find('client_88a388d9dd48f86c3136')
client.email = 'lovely-client@example.com'
client.description = 'My Lovely Client'
client.update
7 changes: 7 additions & 0 deletions samples/offers/create_new_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Paymill::Offer.create(
amount: 4200,
currency: 'EUR',
interval: '1 MONTH',
name: 'Nerd Special',
trial_period_days: 0
)
1 change: 1 addition & 0 deletions samples/offers/export_offers_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/offers/get_offer_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Offer.find('offer_40237e20a7d5a231d99b')
1 change: 1 addition & 0 deletions samples/offers/list_offers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Offer.all()
7 changes: 7 additions & 0 deletions samples/offers/remove_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# with subscriptions:
offer = Paymill::Offer.find('offer_40237e20a7d5a231d99b')
offer.delete_with_subscriptions()

# without subscriptions:
offer = Paymill::Offer.find('offer_40237e20a7d5a231d99b')
offer.delete_without_subscriptions()
8 changes: 8 additions & 0 deletions samples/offers/update_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
offer = Paymill::Offer.find('offer_40237e20a7d5a231d99b')

offer.name = 'Extended Special'
offer.interval = '1 MONTH'
offer.currency = 'USD'
offer.amount = '3333'

offer.update( update_subscriptions: true )
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Payment.create( token: '098f6bcd4621d373cade4e832627b4f6' )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Paymill::Payment.create(
token: '098f6bcd4621d373cade4e832627b4f6',
client: 'client_88a388d9dd48f86c3136'
)
1 change: 1 addition & 0 deletions samples/payments/create_new_debit_payment_with_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Payment.create( token: '12a46bcd462sd3r3care4e8336ssb4f5' )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Paymill::Payment.create(
token: '12a46bcd462sd3r3care4e8336ssb4f5',
client: 'client_88a388d9dd48f86c3136'
)
1 change: 1 addition & 0 deletions samples/payments/export_payments_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not yet implemented
1 change: 1 addition & 0 deletions samples/payments/get_payment_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Payment.find( 'pay_3af44644dd6d25c820a8' )
1 change: 1 addition & 0 deletions samples/payments/list_payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Payment.all
2 changes: 2 additions & 0 deletions samples/payments/remove_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
payment = Paymill::Payment.find( 'pay_ea98515b29437b046207ea45' )
payment.delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')

Paymill::Preauthorization.create(
payment: payment.id,
amount: 4200,
currency: 'EUR',
description: 'description example'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Paymill::Preauthorization.create(
token: '098f6bcd4621d373cade4e832627b4f6',
amount: 4200,
currency: 'EUR',
description: 'description example'
)
1 change: 1 addition & 0 deletions samples/preauthorizations/export_preauthorizations_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/preauthorizations/get_preauthorization_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Preauthorization.find('preauth_31eb90495837447f76b7')
1 change: 1 addition & 0 deletions samples/preauthorizations/list_preauthozizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Preauthorization.all()
2 changes: 2 additions & 0 deletions samples/preauthorizations/remove_preauthorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
preauthorization = Paymill::Preauthorization.find('preauth_31eb90495837447f76b7')
preauthorization.delete
11 changes: 11 additions & 0 deletions samples/refunds/create_new_refund.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
transaction = Paymill::Transaction.create(
token: '098f6bcd4621d373cade4e832627b4f6',
amount: 4200,
currency: 'USD'
)

Paymill::Refund.create(
transaction,
amount: 4200,
description: 'Sample Description'
)
1 change: 1 addition & 0 deletions samples/refunds/export_refunds_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/refunds/get_refund_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Refund.find('refund_87bc404a95d5ce616049')
1 change: 1 addition & 0 deletions samples/refunds/list_refunds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Refund.all()
2 changes: 2 additions & 0 deletions samples/subscriptions/cancel_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.cancel()
15 changes: 15 additions & 0 deletions samples/subscriptions/create_new_subscription_with_an_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
offer = Paymill::Offer.create(
amount: 3333,
currency: 'EUR',
interval: '1 WEEK',
name: 'Nerd Special',
trial_period_days: 30
)

Paymill::Subscription.create(
payment: payment,
offer: offer,
period_of_validity: '2 YEAR',
start_at: 2.days.from_now
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
offer = Paymill::Offer.create(
amount: 4200,
currency: 'EUR',
interval: '1 MONTH',
name: 'Nerd Special',
trial_period_days: 30
)

Paymill::Subscription.create(
payment: payment,
offer: offer,
amount: 3000,
currency: 'EUR',
interval: '1 week, monday',
name: 'Example Subscription',
period_of_validity: '2 YEAR',
start_at: 2.days.from_now
)
13 changes: 13 additions & 0 deletions samples/subscriptions/create_new_subscription_without_an_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
client = Paymill::Client.create(email: 'client@example.com')
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6', client: client)

Paymill::Subscription.create(
payment: payment,
client: client,
name: 'Example Subscription',
amount: 3000,
currency: 'EUR',
interval: '1 week,monday',
period_of_validity: '2 YEAR',
start_at: 2.days.from_now
)
2 changes: 2 additions & 0 deletions samples/subscriptions/delete_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.remove()
1 change: 1 addition & 0 deletions samples/subscriptions/export_subscriptions_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/subscriptions/get_subscription_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Subscription.find("sub_dc180b755d10da324864")
1 change: 1 addition & 0 deletions samples/subscriptions/list_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Subscription.all()
7 changes: 7 additions & 0 deletions samples/subscriptions/pause_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pause:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.pause

#play:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.play
12 changes: 12 additions & 0 deletions samples/subscriptions/update_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.payment = 'pay_95ba26ba2c613ebb0ca8'
subscription.currency = 'USD'
subscription.interval = '1 month,friday'
subscription.name = 'Changed Subscription'
subscription.trial_end = false
subscription.update

# for limit / unlimit use
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.unlimit
subscription.limit('12 MONTH')
7 changes: 7 additions & 0 deletions samples/subscriptions/update_subscription_amount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#amount temporary:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.update_amount_once(1234)

#amount permanently:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
subscription.update_amount_permanently(1234)
14 changes: 14 additions & 0 deletions samples/subscriptions/update_subscription_offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#offer with no refund and unchanged capture date:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
subscription.update_offer_without_changes(offer)

#offer with refund and unchanged capture date:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
subscription.update_offer_with_refund(offer)

#offer with refund and capture date:
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
subscription.update_offer_with_refund_and_capture_date(offer)
8 changes: 8 additions & 0 deletions samples/transactions/create_new_transaction_with_app_fee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Paymill::Transaction.create(
token: '098f6bcd4621d373cade4e832627b4f6',
amount: 4200, currency: 'EUR',
description: 'Test Transaction',
fee_amount: 4200,
fee_payment: 'pay_a818b847db6ce5ff636f',
fee_currency: 'EUR'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
client = Paymill::Client.create(email: 'mail@example.com')
payment = Paymill::Payment.create(
token: '098f6bcd4621d373cade4e832627b4f6',
client: client
)

Paymill::Transaction.create(
payment: payment,
client: client,
amount: 4200,
currency: 'EUR'
)
7 changes: 7 additions & 0 deletions samples/transactions/create_new_transaction_with_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
transaction = Paymill::Transaction.create(
payment: payment,
amount: 4200,
currency: 'EUR',
description: 'Test Transaction'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
preauthorization = Paymill::Preauthorization.create(
token: '098f6bcd4621d373cade4e832627b4f6',
amount: 4200,
currency: 'EUR'
)
transaction = Transaction.create(
preauthorization: preauthorization,
amount: 4200,
currency: 'EUR'
)
6 changes: 6 additions & 0 deletions samples/transactions/create_new_transaction_with_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Paymill::Transaction.create(
token: '098f6bcd4621d373cade4e832627b4f6',
amount: 4200,
currency: 'EUR',
description: 'Test Transaction'
)
1 change: 1 addition & 0 deletions samples/transactions/export_transactions_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/transactions/get_transaction_details_by_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Transaction.find('tran_023d3b5769321c649435')
1 change: 1 addition & 0 deletions samples/transactions/get_transaction_details_by_slv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Transaction.find('tran_023d3b5769321c649435')
1 change: 1 addition & 0 deletions samples/transactions/list_transactions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Transaction.all()
3 changes: 3 additions & 0 deletions samples/transactions/upate_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
transaction = Paymill::Transaction.find('tran_023d3b5769321c649435')
transaction.description = 'My updated transaction description'
transaction.update
5 changes: 5 additions & 0 deletions samples/webhooks/create_new_email_webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Paymill::Webhook.create(
email: 'webhook@example.com',
event_types: ['transaction.succeeded', 'transaction.failed'],
active: false
)
4 changes: 4 additions & 0 deletions samples/webhooks/create_new_url_webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Paymill::Webhook.create(
url: 'http://example.com',
event_types: ['transaction.succeeded', 'transaction.failed']
)
1 change: 1 addition & 0 deletions samples/webhooks/export_webhooks_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Not implemented yet
1 change: 1 addition & 0 deletions samples/webhooks/get_webhook_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paymill::Webhook.find('hook_40237e20a7d5a231d99b')
2 changes: 2 additions & 0 deletions samples/webhooks/remove_webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
webhook = Paymill::Webhook.find(active_webhook_id)
webhook.delete()
3 changes: 3 additions & 0 deletions samples/webhooks/update_webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
webhook = Paymill::Webhook.find(active_webhook_id)
webhook.email = 'mail@example.com'
webhook.update()

0 comments on commit 405b9c7

Please sign in to comment.