Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed tests path in generator #192

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Offsite Payments CHANGELOG

### Version 2.3.0 (February 8, 2016)
- Release 2.3.0

### Version 2.2.0 (October 14, 2015)
- Bump active_utils dependency. [lucasuyezu]

Expand Down
8 changes: 4 additions & 4 deletions generators/integration_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def initialize(*args)
def generate
template "templates/integration.rb", "#{lib}.rb"

template "templates/module_test.rb", "#{test_dir}/integrations/#{identifier}_module_test.rb"
template "templates/helper_test.rb", "#{test_dir}/integrations/#{identifier}_helper_test.rb"
template "templates/notification_test.rb", "#{test_dir}/integrations/#{identifier}_notification_test.rb"
template "templates/module_test.rb", "#{test_dir}/#{identifier}_module_test.rb"
template "templates/helper_test.rb", "#{test_dir}/#{identifier}_helper_test.rb"
template "templates/notification_test.rb", "#{test_dir}/#{identifier}_notification_test.rb"
end

protected
Expand All @@ -46,6 +46,6 @@ def lib
end

def test_dir
"test/unit/integrations"
"test/unit/integrations/#{identifier}"
end
end
170 changes: 170 additions & 0 deletions lib/offsite_payments/integrations/yandex_kassa.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
module OffsitePayments #:nodoc:
module Integrations #:nodoc:
module YandexKassa

mattr_accessor :test_url
self.test_url = 'https://demomoney.yandex.ru/eshop.xml'

mattr_accessor :production_url
self.production_url = 'https://money.yandex.ru/eshop.xml'

def self.service_url
mode = OffsitePayments.mode

case mode
when :production
self.production_url
when :test
self.test_url
else
raise StandardError, 'Integration mode set to an invalid value: #{mode}'
end
end

def self.notification(post, options = {})
Notification.new(post, options)
end

def self.helper(order, account, options = {})
Helper.new(order, account, options)
end

class Helper < OffsitePayments::Helper
mapping :account, 'customerNumber'
mapping :amount, 'sum'
mapping :order, 'orderNumber'
mapping :customer, :email => 'cps_email',
:phone => 'cps_phone'

mapping :success_url, 'shopSuccessURL'
mapping :fail_url, 'shopFailURL'

mapping :scid, 'scid'
mapping :shop_id, 'shopId'
end

class Notification < OffsitePayments::Notification
def currency
id, _ = Money::Currency.table.find {|key, currency| currency[:iso_numeric] == shop_sum_currency_paycash }
id
end

def signature_string
[action, order_sum_amount, order_sum_currency_paycash, order_sum_bank_paycash, shop_id, invoice_id, customer_number]
end

def generate_signature(shop_password)
Digest::MD5.hexdigest((signature_string << shop_password).join(';'))
end

def request_datetime
params['requestDatetime']
end
def action
params['action']
end
def md5
params['md5']
end
def shop_id
params['shopId']
end
def shop_article_id
params['shopArticleId']
end
def invoice_id
params['invoiceId']
end
def order_number
params['orderNumber']
end
def customer_number
params['customerNumber']
end
def order_created_datetime
params['orderCreatedDatetime']
end
def order_sum_amount
params['orderSumAmount']
end
def order_sum_currency_paycash
params['orderSumCurrencyPaycash']
end
def order_sum_bank_paycash
params['orderSumBankPaycash']
end
def shop_sum_amount
params['shopSumAmount']
end
def shop_sum_currency_paycash
params['shopSumCurrencyPaycash']
end
def shop_sum_bank_paycash
params['shopSumBankPaycash']
end
def payment_payer_code
params['paymentPayerCode']
end
def payment_type
params['paymentType']
end

def complete?
case action
when 'checkOrder'
'pending'
when 'paymentAviso'
'complete'
else
'unknown'
end
end

def item_id
shop_article_id
end

def transaction_id
shop_invoice_id
end

# When was this payment received by the client.
def received_at
request_datetime
end

def security_key
md5.to_s.downcase
end

# the money amount we received in X.2 decimal.
def gross
shop_sum_amount.to_f
end

def status
'success'
end

# Acknowledge the transaction to YandexKassa. This method has to be called after a new
# apc arrives. YandexKassa will verify that all the information we received are correct and will return a
# ok or a fail.
#
# Example:
#
# def ipn
# notify = YandexKassaNotification.new(request.raw_post)
#
# if notify.acknowledge
# ... process order ... if notify.complete?
# else
# ... log possible hacking attempt ...
# end
def acknowledge(authcode = nil)
(security_key == generate_signature(authcode))
end

end
end
end
end
2 changes: 1 addition & 1 deletion lib/offsite_payments/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OffsitePayments
VERSION = "2.2.0"
VERSION = "2.3.0"
end
28 changes: 28 additions & 0 deletions test/unit/integrations/yandex_kassa/yandex_kassa_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class YandexKassaHelperTest < Test::Unit::TestCase
include OffsitePayments::Integrations

def setup
@helper = YandexKassa::Helper.new('order-500','[email protected]', :amount => '5.00', :currency => 'RUB')
end

def test_basic_helper_fields
assert_field 'customerNumber', '[email protected]'

assert_field 'sum', '5.00'
assert_field 'orderNumber', 'order-500'
end

def test_customer_fields
@helper.customer :email => '[email protected]'
assert_field 'cps_email', '[email protected]'
end

def test_unknown_mapping
assert_nothing_raised do
@helper.company_address :address => '500 Dwemthy Fox Road'
end
end

end
28 changes: 28 additions & 0 deletions test/unit/integrations/yandex_kassa/yandex_kassa_module_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class YandexKassaTest < Test::Unit::TestCase
include OffsitePayments::Integrations

def test_notification_method
assert_instance_of YandexKassa::Notification, YandexKassa.notification('name=cody')
end

def test_test_mode
OffsitePayments.mode = :test
assert_equal YandexKassa.test_url, YandexKassa.service_url
end

def test_production_mode
OffsitePayments.mode = :production
assert_equal YandexKassa.production_url, YandexKassa.service_url
ensure
OffsitePayments.mode = :test
end

def test_invalid_mode
OffsitePayments.mode = :bro
assert_raise(StandardError){YandexKassa.service_url}
ensure
OffsitePayments.mode = :test
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'test_helper'
require 'pry'
class YandexKassaNotificationTest < Test::Unit::TestCase
include OffsitePayments::Integrations

def setup
@yandex_kassa = YandexKassa::Notification.new(http_raw_data)
end

def test_accessors
assert @yandex_kassa.complete?
assert_equal 86.23, @yandex_kassa.gross
assert_equal :rub, @yandex_kassa.currency
assert_equal "2011-05-04T20:38:00.000 04:00", @yandex_kassa.received_at
end

def test_compositions
assert_equal Money.new(8623, 'RUB'), @yandex_kassa.amount
end

# Replace with real successful acknowledgement code
def test_acknowledgement
assert @yandex_kassa.acknowledge('coolpasswd')
end

def test_respond_to_acknowledge
assert @yandex_kassa.respond_to?(:acknowledge)
end

private
def http_raw_data
"requestDatetime=2011-05-04T20:38:00.000+04:00&md5=38b46a3adae71186d470522f1995e174&invoiceId=1234567&shopId=13&shopArticleId=456&customerNumber=8123294469&orderCreatedDatetime=2011-05-04T20:38:00.000+04:00&paymentPayerCode=42007148320&orderSumAmount=87.10&orderSumCurrencyPaycash=643&orderSumBankPaycash=1001&shopSumAmount=86.23&shopSumCurrencyPaycash=643&shopSumBankPaycash=1001&paymentType=AC"
end
end