Click here to Skip to main content
       

ASP.NET

 
AnswerRe: why it's adding this to the database?!! Pinmemberjkirkerx24-Nov-12 18:10 
Question(This webpage has a redirect loop) Problem Pinmemberjrahma24-Nov-12 11:05 
AnswerRe: (This webpage has a redirect loop) Problem Pinmemberjkirkerx24-Nov-12 18:21 
SuggestionShould i change my asked question? Pinmemberanglo007223-Nov-12 22:29 
GeneralI'm find C# asp.net linkedin sample code PinmemberSerdar Şengül22-Nov-12 21:14 
GeneralRe: I'm find C# asp.net linkedin sample code PinmvpRichard MacCutchan22-Nov-12 23:57 
GeneralRe: I'm find C# asp.net linkedin sample code [modified] PinmemberCommDev8-Dec-12 23:23 
QuestionPaypal Website Payments Standard Integration using NVP [modified] PinmemberZaf Khan22-Nov-12 18:21 
Hello Everyone,
 
I'm trying to integrate Paypal Website Payments Standard into my eStore.
 
I would like to roll my own solution and cannot make sense of the paypal documentation, its very sprawling and there are so many sections that its confusing to say the least.
 
I'm not intending to use PDT or IPN I will use the RETURN variable to assess if the payment went through okay or failed.
 
Maybe at a later date I will integrate PDT and IPN too.
 
I think I can handle the calling and processing the returns.
 
But I'm stuck at some very basic levels....
 
1 - Is this a suitable solution for live use? (no PDT/IPN)
 
2 - Should I calculate discounts or will paypal do it
(using the NVP)
 
3 - Should I calculate shipping or will paypal do it
(using the NVP)
 
4 - Should I calculate taxes or will paypal do it
(using the NVP)
 
5 - What is the order of execution to calculate discounts?
For example.... Is this right?
If CartDiscountAmount > 0 Then
calculate discount based on fixed discount amount
ElseIf CartDiscountRate > 0 Then
calculate discount based on fixed discount rate
Else
calculate discount based on item discount settings
End If
 
6 - What is the order of execution to calculate shipping?
For example.... Is this right?
If CartShippingAmount > 0 Then
calculate shipping based on fixed shipping amount
ElseIf CartShippingRate > 0 Then
calculate shipping based on fixed shipping rate
Else
calculate shipping based on item shipping settings
End If
 
7 - What is the order of execution to calculate taxes?
For example.... Is this right?
If CartTaxAmount > 0 Then
calculate taxes based on fixed tax amount
ElseIf CartTaxRate > 0 Then
calculate taxes based on fixed tax rate
Else
calculate taxes based on item tax settings
End If
 
I have other questions too, but thought i would start at the beginning and ask the other questions as i go along.
 
I'm not asking for code samples.
I'm asking for pointers to go in the right direction.
Please dont refer me to the paypal website via links.
 

Thank You.
 

 
Well, after having enough of trawling the Paypal documentation I decided to write to their support department, upon completing and submitting my query, I was presented with a popup and links to some other documentation which looked a lot cleaner and more targetted at what I wanted.
 
So I wrote the function below to update my cart to the paypal processing server.
 
Please would someone be kind enough to look at it and point out any errors? and also i'm not sure how to process the options field? Any advice or help there would be greatly appreciated.
 
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Structure] Individual Item Options Collection Option Item - Suboption Item
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Structure _IntSuboptionItem
		Dim _OptionSelect As String																								'option_selectX
		Dim _OptionAmount As Long																									'option_amountX
	End Structure
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Structure] Individual Item Options Collection - Option Item
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Structure _IntOption
		Dim _Name As String																												'Payapal OnX
		Dim _Selection As String																									'Paypal OsX
		Dim _OptionIndex As Integer																								'Paypal option_index (column which has prices)
		Dim _Suboptions As Generic.List(Of _IntSuboptionItem)											'see _IntSuboptionItem
	End Structure
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Structure] Individual Item Options Collection 
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Structure _IntOptions
		Dim _Options As Generic.List(Of _IntOption)
	End Structure
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Structure] Individual Item Params
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Structure _IntShoppingCartItem
		Dim _AmountX As Long																											'amount 
		Dim _BlocksX As Integer																										'blocks (qty months)
		Dim _DiscountAmountX As Long																							'discount_amount 
		Dim _DiscountAmount2X As Long																							'discount_amount 2
		Dim _DiscountRateX As Long																								'discount_rate 
		Dim _DiscountRate2X As Long																								'discount_rate 2
		Dim _DiscountNumX As Integer																							'discount_num 
		Dim _ItemNameX As String																									'item_name 
		Dim _ItemNumberX As String																								'item_nunmber
		Dim _QuantityX As Integer																									'quantity
		Dim _ShippingX As Long																										'shipping
		Dim _Shipping2X As Integer																								'shipping2
		Dim _TaxX As Long																													'tax
		Dim _TaxRateX As Integer																									'tax_rate
		Dim _UndefinedQuantitXy As Char																						'undefined_quantity 
		Dim _WeightX As Integer																										'weight
		Dim _WeightUnitX As String																								'weight_unit
		Dim _OptionFieldsX As _IntOptions																					'see _IntOptions
	End Structure
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Structure] Shopping Cart Params
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Structure _IntShoppingCart
		Dim _Add As String																												'add										add item to cart contents
		Dim _Display As String																										'display								display cart contents
		Dim _Upload As String																											'upload									upload cart contents (for payment)
		Dim _Business As String																										'business								the payto email email
		Dim _DiscAmountCart As Long																								'discount_amount_cart
		Dim _DiscRateCart As Integer																							'discount-rate_cart
		Dim _HandlingCart As Long																									'handling_cart
		Dim _PaymentAction As String																							'payment_action
		Dim _ShoppingUrl As String																								'shopping_url
		Dim _Items As Generic.List(Of _IntShoppingCartItem)
	End Structure
 

 
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Function] Upload Cart
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Function UploadCart(oCart As _IntShoppingCart, strShoppingUrl As String) As Boolean
		'
		Dim strReq As String = Nothing
		Dim intItmIdx As Integer = Nothing
		Dim intCounta As Integer = Nothing
		Dim intCountb As Integer = Nothing
		Dim intCountc As Integer = Nothing
		'
		'-> Initialise
		UploadCart = False
		'-> Validate
		If Trim(oCart._Business) <> "" Then
			If ObtainEndpointUrl("nvpapi", "sandbox", "nvp", strReq) Then
				'core
				strReq = strReq & "?cmd=_cart"
				strReq = strReq & "&upload=1"
				strReq = strReq & "&business=" & Trim(oCart._Business)
				strReq = strReq & "&paymentaction=sale"
				'urls
				strReq = strReq & "&shoppingurl=" & strShoppingUrl
				'basket
				If oCart._Items.Count > 0 Then
					For intCounta = 0 To oCart._Items.Count - 1
						intItmIdx = intCounta + 1
						'item-basics
						strReq = strReq & "&item_name_" & intItmIdx & "=" & Trim(oCart._Items(intCounta)._ItemNameX)
						strReq = strReq & "&item_number_" & intItmIdx & "=" & Trim(oCart._Items(intCounta)._ItemNameX)
						If oCart._Items(intCounta)._QuantityX > 0 Then
							strReq = strReq & "&quantity_" & intItmIdx & "=" & Trim(oCart._Items(intCounta)._QuantityX)
						Else
							strReq = strReq & "&undefinedquantity=1"
						End If
						If oCart._Items(intCounta)._BlocksX > 0 Then
							strReq = strReq & "&amount_" & intItmIdx & "=" & FormatBlockPrice(oCart._Items(intCounta)._BlocksX, oCart._Items(intCounta)._QuantityX, oCart._Items(intCounta)._AmountX)
						Else
							strReq = strReq & "&amount_" & intItmIdx & "=" & FormatBlockPrice(0, oCart._Items(intCounta)._QuantityX, oCart._Items(intCounta)._AmountX)
						End If
						'discounts
						If oCart._DiscAmountCart > 0 Then
							strReq = strReq & "&discount_amount_cart=" & FormatPrice(oCart._DiscAmountCart)
						ElseIf oCart._DiscRateCart > 0 Then
							strReq = strReq & "&discount_rate_cart=" & FormatPrice(oCart._DiscRateCart)
						Else
							If oCart._Items(intCounta)._DiscountAmountX > 0 Then
								strReq = strReq & "&discount_amount_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._DiscountAmountX)
								If oCart._Items(intCounta)._DiscountAmount2X > 0 Then strReq = strReq & "&discount_amount2_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._DiscountAmount2X)
							End If
							If oCart._Items(intCounta)._DiscountRateX > 0 Then
								strReq = strReq & "&discount_rate_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._DiscountRateX)
								If oCart._Items(intCounta)._DiscountRate2X > 0 Then strReq = strReq & "&discount_rate2_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._DiscountRate2X)
							End If
							If oCart._Items(intCounta)._DiscountAmount2X > 0 Or oCart._Items(intCounta)._DiscountRate2X > 0 Then strReq = strReq & "&discount_num_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._DiscountNumX)
						End If
						'shipping
						If oCart._HandlingCart > 0 Then
							strReq = strReq & "&handling_cart=" & FormatPrice(oCart._HandlingCart)
						Else
							If oCart._Items(intCounta)._ShippingX > 0 Then
								strReq = strReq & "&shipping_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._ShippingX)
								If oCart._Items(intCounta)._Shipping2X > 0 Then strReq = strReq & "&shipping2_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._Shipping2X)
							End If
						End If
						'tax
						If oCart._Items(intCounta)._TaxX > 0 Then
							strReq = strReq & "&tax_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._TaxX)
						ElseIf oCart._Items(intCounta)._TaxRateX > 0 Then
							strReq = strReq & "&tax_rate_" & intItmIdx & "=" & FormatBlockPrice(oCart._Items(intCounta)._BlocksX, oCart._Items(intCounta)._QuantityX, oCart._Items(intCounta)._TaxRateX)
						End If
						'metrics
						If oCart._Items(intCounta)._WeightX > 0 Then
							strReq = strReq & "&weight_" & intItmIdx & "=" & FormatPrice(oCart._Items(intCounta)._WeightX)
							If Trim(LCase(oCart._Items(intCounta)._WeightUnitX)) = "kgs" Then
								strReq = strReq & "&weight_unit_" & intItmIdx & "=kgs"
							Else
								strReq = strReq & "&weight_unit_" & intItmIdx & "=lbs"
							End If
						End If
						'options
						If oCart._Items(intCounta)._OptionFieldsX._Options.Count > 0 Then
							For intCountb = 0 To oCart._Items(intCounta)._OptionFieldsX._Options.Count - 1
								strReq = strReq & "&on" & intCounta & "_" & intCountb & "=" & Trim(oCart._Items(intCounta)._OptionFieldsX._Options(intCountb)._Name)
								For intCountc = 0 To oCart._Items(intCounta)._OptionFieldsX._Options(intCountb)._Suboptions.Count - 1
									'option_select?
									'option_amount?
								Next
							Next
						End If
					Next
				End If
			Else
				'error - failed to obtain endpointurl
			End If
		Else
			'error - business name missing
		End If
		intCounta = Nothing
		intCountb = Nothing
		intCountc = Nothing
		intItmIdx = Nothing
		strReq = Nothing
		'
	End Function
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Function] FormatBlockPrice
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Private Function FormatBlockPrice(intBlocks As Integer, intQuantity As Integer, lngValue As Long) As String
		'
		FormatBlockPrice = "0.00"
		If intBlocks > 0 Then
			If intQuantity > 1 Then
				FormatBlockPrice = FormatPrice((intQuantity * lngValue) * intBlocks)
			ElseIf intQuantity = 1 Then
				FormatBlockPrice = FormatPrice(lngValue * intBlocks)
			End If
		Else
			If intQuantity > 1 Then
				FormatBlockPrice = FormatPrice(intQuantity * lngValue)
			ElseIf intQuantity = 1 Then
				FormatBlockPrice = FormatPrice(lngValue)
			End If
		End If
		'
	End Function
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Function] FormatPrice
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Private Function FormatPrice(lngValue As Long) As String
		'
		FormatPrice = "0.00"
		If lngValue > 0 Then FormatPrice = FormatNumber(lngValue, 2, TriState.True)
		'
	End Function
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	'-> [Function] EndpointUrl
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------
	Private Function ObtainEndpointUrl(strAuthentication As String, strEnvironment As String, strFormat As String, ByRef strRtnEndpoint As String) As Boolean
		'
		'-> Endpoint Definitions (DefaultAuthentication=Signature/DefaultEnvironment=Sandbox/DefaultFormat=NVP)
		'Environment		Authentication											Calling								Endpoint
		'Live						API Certificate											SOAP									https://api.paypal.com/2.0/
		'Live						API Certificate											Name-Value Pair				https://api.paypal.com/nvp
		'Sandbox				API Certificate											SOAP									https://api.sandbox.paypal.com/2.0/
		'Sandbox				API Certificate											Name-Value Pair				https://api.sandbox.paypal.com/nvp
		'Live						Adaptive APIs												JSON, NVP, XML				https://svcs.paypal.com/AdaptivePayments/API_operation
		'Sandbox				Adaptive APIs												JSON, NVP, XML				https://svcs.sandbox.paypal.com/AdaptivePayments/API_operation 
		'Live						Permissions Service APIs						JSON, NVP, SOAP				https://svcs.paypal.com/Permission/API_operation
		'Sandbox				Permissions Service APIs						JSON, NVP, SOAP  			https://svcs.sandbox.paypal.com/Permission/API_operation
		'Live						API Signature												SOAP									https://api-3t.paypal.com/2.0/
		'Live						API Signature												Name-Value Pair				https://api-3t.paypal.com/nvp
		'Sandbox				API Signature												SOAP									https://api-3t.sandbox.paypal.com/2.0/
		'Sandbox				API Signature												Name-Value Pair				https://api-3t.sandbox.paypal.com/nvp
		'
		strRtnEndpoint = ""
		ObtainEndpointUrl = False
		Select Case strAuthentication
			Case "apicertificate"
				If strEnvironment = "live" Then
					If strFormat = "soap" Then
						strRtnEndpoint = "https://api.paypal.com/2.0/"
					Else
						strRtnEndpoint = "https://api.paypal.com/nvp"
					End If
				Else
					If strFormat = "soap" Then
						strRtnEndpoint = "https://api.sandbox.paypal.com/2.0/"
					Else
						strRtnEndpoint = "https://api.sandbox.paypal.com/nvp"
					End If
				End If
			Case "adaptiveapis"
				If strEnvironment = "live" Then
					strRtnEndpoint = "https://svcs.paypal.com/AdaptivePayments/API_operation"
				Else
					strRtnEndpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/API_operation"
				End If
			Case "permissionsapis"
				If strEnvironment = "live" Then
					strRtnEndpoint = "https://svcs.paypal.com/Permission/API_operation"
				Else
					strRtnEndpoint = "https://svcs.sandbox.paypal.com/Permission/API_operation"
				End If
			Case Else
				If strEnvironment = "live" Then
					If strFormat = "soap" Then
						strRtnEndpoint = "https://api-3t.paypal.com/2.0/"
					Else
						strRtnEndpoint = "https://api-3t.paypal.com/nvp"
					End If
				Else
					If strFormat = "soap" Then
						strRtnEndpoint = "https://api-3t.sandbox.paypal.com/2.0/"
					Else
						strRtnEndpoint = "https://api-3t.sandbox.paypal.com/nvp"
					End If
				End If
		End Select
		ObtainEndpointUrl = (Trim(strRtnEndpoint) <> "")
		'
	End Function
	'-------------------------------------------------------------------------------------------------------------------------------------------------------------


modified 23-Nov-12 5:48am.

AnswerRe: Paypal Website Payments Standard Integration using NVP Pinmemberjkirkerx24-Nov-12 19:59 
GeneralRe: Paypal Website Payments Standard Integration using NVP PinmemberZaf Khan24-Nov-12 22:07 
GeneralRe: Paypal Website Payments Standard Integration using NVP Pinmemberjkirkerx25-Nov-12 8:08 
GeneralRe: Paypal Website Payments Standard Integration using NVP PinmemberZaf Khan25-Nov-12 19:44 
QuestionProblem With List View Pinmemberggaurav bhandari22-Nov-12 2:09 
AnswerRe: Problem With List View PinmemberParwej Ahamad22-Nov-12 6:08 
GeneralRe: Problem With List View Pinmemberd0cvb22-Nov-12 10:28 
GeneralRe: Problem With List View PinmemberParwej Ahamad22-Nov-12 18:35 
QuestionChecking the size of a cookie Pinmembersuzyb22-Nov-12 1:46 
AnswerRe: Checking the size of a cookie PinmemberZaf Khan23-Nov-12 6:04 
GeneralRe: Checking the size of a cookie Pinmembersuzyb23-Nov-12 9:49 
GeneralRe: Checking the size of a cookie PinmemberZaf Khan23-Nov-12 11:43 
QuestionRemove tick/check box from ASP.NET Checkbox control Pinmemberthes@int21-Nov-12 6:48 
AnswerRe: Remove tick/check box from ASP.NET Checkbox control Pinmemberjkirkerx21-Nov-12 12:46 
Questionweb service creation PinmemberMember 961924321-Nov-12 6:17 
AnswerRe: web service creation Pinmembermark merrens21-Nov-12 6:24 
QuestionReturn multiple result set to Generic List Pinmemberyesu prakash20-Nov-12 23:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 25 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid