Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
Hotfix release available: 2025-05-14a "Librarian". upgrade now! [56.1] (what's this?)
New release available: 2025-05-14 "Librarian". upgrade now! [56] (what's this?)
Hotfix release available: 2024-02-06b "Kaos". upgrade now! [55.2] (what's this?)
Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04b "Jack Jackrum". upgrade now! [54.2] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
New release available: 2020-07-29 "Hogfather". upgrade now! [51.3] (what's this?)
New release candidate 3 available: 2020-06-09 "Hogfather". upgrade now! [51.2] (what's this?)
New release candidate 2 available: 2020-06-01 "Hogfather". upgrade now! [51.1] (what's this?)
New release candidate available: 2020-06-01 "Hogfather". upgrade now! [51] (what's this?)
Hotfix release available: 2018-04-22c "Greebo". upgrade now! [50.3] (what's this?)
Hotfix release available: 2018-04-22b "Greebo". upgrade now! [50.2] (what's this?)
payment_integration

Requirements

Support for paying using any of the following:

  • Credit cards (Visa, MC, Discover, American Express, Diners Club and JCB from anywhere in the world)
  • Paypal
  • Purchase Orders

Support for:

  • one time transaction
  • recurring billing
  • verifications
  • refunds
  • merchant account

Support PayPal and TrustCommerce payment gateways.

Implementation

We will be using the ActiveMerchant library to communicate with the payment gateways. At present, we do not handle merchant account verification.

Merchant Account details

The following Models will be used for Implementation

class MerchantAccount < ActiveRecord::Base 
  belongs_to :owner, :polymorphic => true
end 

class PayPalAccount < MerchantAccount; end

class TrustCommerceAccount < MerchantAccount; end

class User < ActiveRecord::Base
  has_one :merchant_account, as => :owner
  #rest of the code...
end

class Company < ActiveRecord::Base
  has_one :merchant_account, as => :owner
  #rest of the code...
end

Table name - merchant_accounts

Column_name type Description
id integer primary key
owner_id integer references to either company or user table
owner_type varchar type of the owner. Company or User
login varchar username to connect to the payment gateway
password varchar password to connect to the payment gatewy
signature varchar Paypal api signature. Required only in case of paypal
type varchar type of the payment Gateway. This will be populated by Rails (STI)
create_at date_time created date
updated_at date_timeupdated date

PayPalAccount, TrustCommerceAccount will have a method named 'gateway' which will return the appropriate gateway. Using this, we do the payment transactions like purchase, refund, etc.

Payment details

Table name - payments

Column_name type Description
id integer primary key
payer_id integer Which user is making the transaction
payee_id integer To whose merchant account the money credited
payee_type varchar merchant account owner type
ip_address varchar The ip address of the system which initiated this payment
invoice_id integer foreign key to the invoice table. Invoice table will have the details of the purchase items
status varchar Status of the last transaction
create_at date_time created date
updated_at date_timeupdated date

Table name - payment_transactions

Column_name type Description
id integer primary key
payment_id integer Which user is making the transaction
action string This would be the name of the api call ie authorization, purchase, credit etc
amount money
success boolean whether the transaction was successful or not
authorization varchar authorization code
message varchar full message from the response
params varchar all the extra parameters the gateway may return
create_at date_time created date
updated_at date_timeupdated date

Testing

Set up merchant account details for the company - This can be done by clicking on manage site in the header and then choosing 'Merchant account' in the left navigation panel.

To set up paypal merchant - choose Merchant/Account Type - Paypal

Provide - Login Id, Password, Signature and Email. (These information are available under 'API Credentials' in paypal account. To create a paypal test account please visit https://developer.paypal.com/)

Below is details of paypal account that can be used for testing.

Login Id - amit14_1323436529_biz_api1.yahoo.com
Password - 1323436591
Signature - AeSu1oSA5s1Xtx06SgrpgHvWceDGAkCsowCNLQ7qfmk5KJ0zcxYOPzx1
email - amit14_1323436529_biz@yahoo.com


Test Account:	test_1343245835_biz@learnexa.com	
API Username:	test_1343245835_biz_api1.learnexa.com
API Password:	1343245872
Signature:	 AsHT7X-nCMJGqg8KKzXyWbit-LZPAfnYhw0LYLAm-0z1801XlJ-SLhbV	

Once the companies merchant account is setup, then buy some courses/certification/live event. In the checkout page, Provide the card details, if you choose the payment method as Credit Card. Also provide the billing Address. Once the details are filled in, click on 'Place your order' button to process the payment. Once the payment is successful, the user will be redirected to the my_learning page.

If you choose paypal as the payment method, clicking on 'place your order' will open up a window asking for your login to paypal account. Once you login, It will show the details of the payment that you are making.

For paying via paypal, please ensure that a site wide paypal account is created and the details are provided in config/paypal_adaptive.yml file. We have set up a valid account for development/staging/test environment.

For Paypal Adaptive

Platform: Web

Application description and Api used:

Use case: The buyers and sellers are users in the application(learnexa). Multiple products can be purchased by the buyer. A product can be one time purchase or subscription type which can be renewed every month. Learnexa provides potential sellers to create and sell products. Because of the services provided by learnexa a certain percentage of the sale amount will be paid to the learnexa.

Adaptive apis currently used

/AdaptivePayments/Pay - To make transfer the payment to the seller. /AdaptivePayments/Preapproval - Used if the product is a subscription based product. With maxTotalAmountOfAllPayments = purchase amount * 12, maxNumberOfPayments = 30, startingDate = Date when payment is made, endingDate = Start data + 11 months.

Services used by App: - Basic payments - Chained payments - Pre approvals (using Subscription). The pre approval terms are

maxTotalAmountOfAllPayments = purchase amount * 12
maxNumberOfPayments = 30,
startingDate = Date when payment is made,
endingDate = Start data + 11 months

Things to check in case the payments are not happening

1. For CC payments to succeed following needs to be checked

  1. the Receiver's (site) Merchant account setup in Manage Site ⇒ Merchant account needs correct api username, password and signature.
  2. If the logs/payment_transactions table shows “Invalid security header..” for failed CC payment errors, most likely the merchant has not put correct api username, password and signature values in Merchant account settings.
  3. If the logs/payment_transactions table show “Merchant account was not setup properly” then need to ensure that receiver's paypal account should have a Business setup. In order to to receive direct CC payments a business paypal setup is required. When setting up a test store I select an account with “PayPal Payments Pro (Use to represent yourself as a merchant using Pro)” option. I am attaching the screen shot of how the paypal account looks like for such account (note that right panel has “My Business Setup”).

2. For Pay Via Paypal option

  1. If the log shows “The X-PAYPAL-APPLICATION-ID header contains an invalid value”. Then the paypal_adaptive.yml might not have correct values for the environment. The Pay Via Paypal uses Paypal Adaptive method to chain the payments. There are 3 parties involved in the payments.
1) The person who is buying the product. This is the payer/sender.
2) The primary receiver, who will receive the payment first and will distribute it to secondary receivers. This, in our case is learnexa. So we require a paypal account for learnexa too.
3) The person who will finally receive the payment, also called secondary receiver i.e. the company/sub-site in e.g. methodyoga 
payment_integration.txt · Last modified: 2018/08/31 16:16 (external edit)