====== 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 [[http://activemerchant.org/|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_time|updated 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_time|updated 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_time|updated 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. ===== Paypal related information ===== ==== 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 - the Receiver's (site) Merchant account setup in Manage Site => Merchant account needs correct api username, password and signature. - 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. - 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"). {{:paypal_payments_pro_account.png|}} 2. For Pay Via Paypal option - 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