Skip to content
Permalink
Browse files

Add Gateway for Integration with Paypal Express for Digital Goods

(cherry picked from commit cc0db37)

Conflicts:

	lib/active_merchant/billing/gateways/paypal_express.rb
  • Loading branch information...
kenmazaika committed May 19, 2011
1 parent 2cedd85 commit 63a81d0e167a6391c7042ba6df8aab7176644e1b
@@ -0,0 +1,43 @@
require File.dirname(__FILE__) + '/paypal/paypal_common_api'
require File.dirname(__FILE__) + '/paypal/paypal_express_response'
require File.dirname(__FILE__) + '/paypal_express_common'

module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalDigitalGoodsGateway < PaypalExpressGateway
self.test_redirect_url = 'https://www.sandbox.paypal.com/incontext'
self.live_redirect_url = 'https://www.paypal.com/incontext'

self.supported_countries = ['US']
self.homepage_url = 'https://www.x.com/community/ppx/xspaces/digital_goods'
self.display_name = 'PayPal Express Checkout for Digital Goods'

def redirect_url_for(token, options = {})
"#{redirect_url}?token=#{token}&useraction=commit"
end

# GATEWAY.setup_purchase(100,
# :ip => "127.0.0.1",
# :description => "Test Title",
# :return_url => "http://return.url",
# :cancel_return_url => "http://cancel.url",
# :items => [ { :name => "Charge",
# :number => "1",
# :quantity => "1",
# :amount => 100,
# :description => "Description",
# :category => "Digital" } ] )
def build_setup_request(action, money, options)
requires!(options, :items)
raise ArgumentError, "Must include at least 1 Item" unless options[:items].length > 0
options[:items].each do |item|
requires!(item, :name, :number, :quantity, :amount, :description, :category)
raise ArgumentError, "Each of the items must have the category 'Digital'" unless item[:category] == 'Digital'
end

super
end

end
end
end
@@ -221,6 +221,7 @@ def add_items_xml(xml, options, currency_code)
end
xml.tag! 'n2:Description', item[:description]
xml.tag! 'n2:ItemURL', item[:url]
xml.tag! 'n2:ItemCategory', item[:category] if item[:category]
end
end
end
@@ -2,8 +2,8 @@ module ActiveMerchant
module Billing
module PaypalExpressCommon
def self.included(base)
base.cattr_accessor :test_redirect_url
base.cattr_accessor :live_redirect_url
base.class_inheritable_accessor :test_redirect_url
base.class_inheritable_accessor :live_redirect_url
base.live_redirect_url = 'https://www.paypal.com/cgibin/webscr'
end

@@ -22,4 +22,4 @@ def redirect_url_for(token, options = {})
end
end
end
end
end
@@ -0,0 +1,122 @@
require 'test_helper'

class PaypalDigitalGoodsTest < Test::Unit::TestCase
TEST_REDIRECT_URL = 'https://www.sandbox.paypal.com/incontext?token=1234567890&useraction=commit'
LIVE_REDIRECT_URL = 'https://www.paypal.com/incontext?token=1234567890&useraction=commit'

def setup
@gateway = PaypalDigitalGoodsGateway.new(
:login => 'cody',
:password => 'test',
:pem => 'PEM'
)

Base.gateway_mode = :test
end

def teardown
Base.gateway_mode = :test
end

def test_live_redirect_url
Base.gateway_mode = :production
assert_equal LIVE_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
end

def test_test_redirect_url
assert_equal :test, Base.gateway_mode
assert_equal TEST_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
end

def test_setup_request_invalid_requests
assert_raise ArgumentError do
@gateway.setup_purchase(100,
:ip => "127.0.0.1",
:description => "Test Title",
:return_url => "http://return.url",
:cancel_return_url => "http://cancel.url")
end

assert_raise ArgumentError do
@gateway.setup_purchase(100,
:ip => "127.0.0.1",
:description => "Test Title",
:return_url => "http://return.url",
:cancel_return_url => "http://cancel.url",
:items => [ ])
end

assert_raise ArgumentError do
@gateway.setup_purchase(100,
:ip => "127.0.0.1",
:description => "Test Title",
:return_url => "http://return.url",
:cancel_return_url => "http://cancel.url",
:items => [ Hash.new ] )
end

assert_raise ArgumentError do
@gateway.setup_purchase(100,
:ip => "127.0.0.1",
:description => "Test Title",
:return_url => "http://return.url",
:cancel_return_url => "http://cancel.url",
:items => [ { :name => "Charge",
:number => "1",
:quantity => "1",
:amount => 100,
:description => "Description",
:category => "Physical" } ] )
end
end


def test_build_setup_request_valid
@gateway.expects(:ssl_post).returns(successful_setup_response)

@gateway.setup_purchase(100,
:ip => "127.0.0.1",
:description => "Test Title",
:return_url => "http://return.url",
:cancel_return_url => "http://cancel.url",
:items => [ { :name => "Charge",
:number => "1",
:quantity => "1",
:amount => 100,
:description => "Description",
:category => "Digital" } ] )

end


private

def successful_setup_response
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/12/secext\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:ns=\"urn:ebay:api:PayPalAPI\">
<SOAP-ENV:Header>
<Security xmlns=\"http://schemas.xmlsoap.org/ws/2002/12/secext\" xsi:type=\"wsse:SecurityType\"></Security>
<RequesterCredentials xmlns=\"urn:ebay:api:PayPalAPI\" xsi:type=\"ebl:CustomSecurityHeaderType\">
<Credentials xmlns=\"urn:ebay:apis:eBLBaseComponents\" xsi:type=\"ebl:UserIdPasswordType\">
<Username xsi:type=\"xs:string\"></Username>
<Password xsi:type=\"xs:string\"></Password>
<Signature xsi:type=\"xs:string\">OMGOMGOMGOMGOMG</Signature>
<Subject xsi:type=\"xs:string\"></Subject>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body id=\"_0\">
<SetExpressCheckoutResponse xmlns=\"urn:ebay:api:PayPalAPI\">
<Timestamp xmlns=\"urn:ebay:apis:eBLBaseComponents\">2011-05-19T20:13:30Z</Timestamp>
<Ack xmlns=\"urn:ebay:apis:eBLBaseComponents\">Success</Ack>
<CorrelationID xmlns=\"urn:ebay:apis:eBLBaseComponents\">da0ed6bc90ef1</CorrelationID>
<Version xmlns=\"urn:ebay:apis:eBLBaseComponents\">72</Version>
<Build xmlns=\"urn:ebay:apis:eBLBaseComponents\">1882144</Build>
<Token xsi:type=\"ebl:ExpressCheckoutTokenType\">EC-0XOMGOMGOMG</Token>
</SetExpressCheckoutResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"
end

end

0 comments on commit 63a81d0

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.