To see a completed integration in a Ruby on Rails app, visit this repository.
Add these lines to your application's Gemfile:
gem 'promisepay'
And then execute:
$ bundle
Or install it yourself as:
$ gem install promisepay
Before interacting with Promispay API you need to generate an access token.
See PromisePay documentation for more information.
Create a PromisePay client
The client can be configured through environment variables.
# In your environment file
PROMISEPAY_USERNAME ||= youremailaddress
PROMISEPAY_TOKEN ||= y0urt0k3n12345678910123456789101
The following parameters are configurable through the client:
:username
/ENV['PROMISEPAY_USERNAME']
: username for basic authentication:token
/ENV['PROMISEPAY_TOKEN']
: token for basic authentication:environment
/ENV['PROMISEPAY_ENVIRONMENT']
: API environment to use (default: 'test'):api_domain
/ENV['PROMISEPAY_API_DOMAIN']
: API domain name to use (default: 'api.promisepay.com')
Instantiate the PromisePay client.
client = Promisepay::Client.new(username: ENV['PROMISEPAY_USERNAME'], token: ENV['PROMISEPAY_TOKEN'])
The below example shows the controller request for a marketplace configured to have the Item and User IDs generated automatically for them. Note: by default, the ability to have PromisePay auto generate IDs is turned off. However, it can easily be requested by contacting PromisePay support.
token_request = client.tokens.create(:session, {
current_user: 'seller',
item_name: 'Test Item',
amount: '2500',
seller_lastname: 'Seller',
seller_firstname: 'Sally',
buyer_lastname: 'Buyer',
buyer_firstname: 'Bobby',
buyer_country: 'AUS',
seller_country: 'USA',
seller_email: '[email protected]',
buyer_email: '[email protected]',
fee_ids: [],
payment_type_id: 2
})
token = token_request['token']
item_id = token_request['item']
buyer_id = token_request['buyer']
seller_id = token_request['seller']
The below example shows the request for a marketplace that passes the Item and User IDs.
token = client.tokens.create(:session, {
current_user_id: 'seller1234',
item_name: 'Test Item',
amount: '2500',
seller_lastname: 'Seller',
seller_firstname: 'Sally',
buyer_lastname: 'Buyer',
buyer_firstname: 'Bobby',
buyer_country: 'AUS',
seller_country: 'USA',
seller_email: '[email protected]',
buyer_email: '[email protected]',
external_item_id: 'TestItemId1234',
external_seller_id: 'seller1234',
external_buyer_id: 'buyer1234',
fee_ids: [],
payment_type_id: 2
})['token']
item = client.items.create(
id: '12345',
name: 'test item for 5AUD',
amount: '500',
payment_type: '1',
buyer_id: buyer.id,
seller_id: seller.id,
fee_ids: fee.id,
description: '5AUD transfer'
)
item = client.items.find('1')
items = client.items.find_all
item.update(name: 'new name')
item.cancel
item.status
item.buyer
item.seller
item.fees
item.transactions
item.batch_transactions
item.wire_details
item.bpay_details
user = client.users.create(
id: '123456',
first_name: 'test',
last_name: 'buyer',
email: '[email protected]',
address_line1: '48 collingwood',
state: 'vic',
city: 'Mel',
zip: '3000',
country: 'AUS',
dob:'12/06/1980'
)
user = client.users.update(
id: '123456',
first_name: 'test',
last_name: 'buyer',
email: '[email protected]',
address_line1: '48 collingwood',
state: 'vic',
city: 'Mel',
zip: '3000',
country: 'AUS',
dob:'12/06/1980'
)
user = client.users.find('1')
users = client.users.find_all
user.card_account
user.paypal_account
user.bank_account
user.wallet_account
user.items
user.address
user.disbursement_account(bank_account.id)
item.make_payment(
account_id: buyer_card_account.id
)
item.request_payment
item.release_payment
item.request_release
item.cancel
item.acknowledge_wire
item.acknowledge_paypal
item.revert_wire
item.request_refund(
refund_amount: '1000',
refund_message: 'because'
)
item.decline_refund
item.refund(
refund_amount: '1000',
refund_message: 'because'
)
item.raise_dispute(user_id: '5830def0-ffe8-11e5-86aa-5e5517507c66')
item.request_resolve_dispute
item.resolve_dispute
item.escalate_dispute
item.send_tax_invoice
item.request_tax_invoice
card_account = client.card_accounts.create(
user_id: buyer.id,
full_name: 'test Buyer',
number: '4111 1111 1111 1111',
expiry_month: Time.now.month,
expiry_year: Time.now.year + 1,
cvv: '123'
)
card_account = client.card_accounts.find('1')
card_account.deactivate
card_account.user
bank_account = client.bank_accounts.create(
user_id: seller.id,
bank_name: 'Nab',
account_name: 'test seller',
routing_number: '22222222',
account_number: '1234567890',
account_type: 'savings',
holder_type: 'personal',
country: 'AUS'
)
bank_account = client.bank_accounts.find('1')
bank_account.deactivate
bank_account.user
client.bank_accounts.validate('122235821')
paypal_account = client.paypal_accounts.create(
user_id: seller.id,
paypal_email: '[email protected]'
)
paypal_account = client.paypal_accounts.find('1')
paypal_account.deactivate
paypal_account.user
wallet_account = client.wallet_accounts.find('1')
wallet_account.deposit(
account_id: '123',
amount: 500
)
wallet_account.withdraw(
account_id: '123',
amount: 200
)
wallet_account.user
client.companies.create(
user_id: "1",
name: "Acme Co",
legal_name: "Acme Co Pty Ltd",
tax_number: "1231231",
charge_tax: true,
address_line1: "123 Test St",
address_line2: "",
city: "Melbourne",
state: "VIC",
zip: "3000",
country: "AUS"
)
client.companies.find('compamy_id')
client.companies.find_all
company.address
client.companies.update(
id: "8d578b9c-5b79-11e5-885d-feff819cdc9f",
name: "Acme Co",
legal_name: "Acme Co Pty Ltd",
tax_number: "1231231",
charge_tax: true,
address_line1: "123 Test St",
address_line2: "",
city: "Melbourne",
state: "VIC",
zip: "3000",
country: "AUS"
)
fees = client.fees.find_all
fees = client.fees.find('1')
fee = client.fees.create(
name: 'test fee for 5 AUD',
fee_type_id: '1',
amount: '75',
to: 'seller'
)
transactions = client.transactions.find_all
transaction = client.transactions.find('1')
transaction.users
transaction.fees
batch_transactions = client.batch_transactions.find_all
batch_transaction = client.batch_transactions.find('1')
charges = client.charges.find_all
charge = client.charges.find('1')
charge = client.charges.create(
account_id: '123',
user_id: '456',
name: 'Charge for Delivery',
email: '[email protected]',
amount: 4_500,
zip: '3000',
curency: 'AUD',
country: 'AUS',
retain_account: true,
device_id: '0900JapG4txqVP4Nf...',
ip_address: '172.16.81.100'
)
charge.buyer
charge.status
bank_account = client.bank_accounts.find('9fda18e7-b1d3-4a83-830d-0cef0f62cd25')
ddas = client.charges.find_all(bank_account.id)
dda = client.direct_debit_authorities.find('8f233e04-ffaa-4c9d-adf9-244853848e21')
charge = client.direct_debit_authorities.create(
account_id: '9fda18e7-b1d3-4a83-830d-0cef0f62cd25',
amount: '10000'
)
dda = client.direct_debit_authorities.find('8f233e04-ffaa-4c9d-adf9-244853848e21')
dda.delete
client.tools.health_check
client.marketplace
client.generate_token(token_type: 'card', user_id: '5830def0-ffe8-11e5-86aa-5e5517507c66')
Check out the online documentation to get a full list of available resources and methods.
- Fork it ( https://github.com/PromisePay/promisepay-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request