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 _IntSuboptionItem
Dim _OptionSelect AsStringDim _OptionAmount AsLongEndStructureStructure _IntOption
Dim _Name AsStringDim _Selection AsStringDim _OptionIndex AsIntegerDim _Suboptions As Generic.List(Of _IntSuboptionItem) EndStructureStructure _IntOptions
Dim _Options As Generic.List(Of _IntOption)
EndStructureStructure _IntShoppingCartItem
Dim _AmountX AsLongDim _BlocksX AsIntegerDim _DiscountAmountX AsLongDim _DiscountAmount2X AsLongDim _DiscountRateX AsLongDim _DiscountRate2X AsLongDim _DiscountNumX AsIntegerDim _ItemNameX AsStringDim _ItemNumberX AsStringDim _QuantityX AsIntegerDim _ShippingX AsLongDim _Shipping2X AsIntegerDim _TaxX AsLongDim _TaxRateX AsIntegerDim _UndefinedQuantitXy AsCharDim _WeightX AsIntegerDim _WeightUnitX AsStringDim _OptionFieldsX As _IntOptions EndStructureStructure _IntShoppingCart
Dim _Add AsStringDim _Display AsStringDim _Upload AsStringDim _Business AsStringDim _DiscAmountCart AsLongDim _DiscRateCart AsIntegerDim _HandlingCart AsLongDim _PaymentAction AsStringDim _ShoppingUrl AsStringDim _Items As Generic.List(Of _IntShoppingCartItem)
EndStructure
Function UploadCart(oCart As _IntShoppingCart, strShoppingUrl AsString) AsBooleanDim strReq AsString = NothingDim intItmIdx AsInteger = NothingDim intCounta AsInteger = NothingDim intCountb AsInteger = NothingDim intCountc AsInteger = Nothing UploadCart = FalseIf Trim(oCart._Business) <> ""ThenIf ObtainEndpointUrl("nvpapi", "sandbox", "nvp", strReq) Then strReq = strReq & "?cmd=_cart"
strReq = strReq & "&upload=1"
strReq = strReq & "&business="& Trim(oCart._Business)
strReq = strReq & "&paymentaction=sale" strReq = strReq & "&shoppingurl="& strShoppingUrl
If oCart._Items.Count > 0ThenFor intCounta = 0To oCart._Items.Count - 1
intItmIdx = intCounta + 1 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 > 0Then
strReq = strReq & "&quantity_"& intItmIdx & "="& Trim(oCart._Items(intCounta)._QuantityX)
Else
strReq = strReq & "&undefinedquantity=1"EndIfIf oCart._Items(intCounta)._BlocksX > 0Then
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)
EndIfIf oCart._DiscAmountCart > 0Then
strReq = strReq & "&discount_amount_cart="& FormatPrice(oCart._DiscAmountCart)
ElseIf oCart._DiscRateCart > 0Then
strReq = strReq & "&discount_rate_cart="& FormatPrice(oCart._DiscRateCart)
ElseIf oCart._Items(intCounta)._DiscountAmountX > 0Then
strReq = strReq & "&discount_amount_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._DiscountAmountX)
If oCart._Items(intCounta)._DiscountAmount2X > 0Then strReq = strReq & "&discount_amount2_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._DiscountAmount2X)
EndIfIf oCart._Items(intCounta)._DiscountRateX > 0Then
strReq = strReq & "&discount_rate_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._DiscountRateX)
If oCart._Items(intCounta)._DiscountRate2X > 0Then strReq = strReq & "&discount_rate2_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._DiscountRate2X)
EndIfIf oCart._Items(intCounta)._DiscountAmount2X > 0Or oCart._Items(intCounta)._DiscountRate2X > 0Then strReq = strReq & "&discount_num_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._DiscountNumX)
EndIfIf oCart._HandlingCart > 0Then
strReq = strReq & "&handling_cart="& FormatPrice(oCart._HandlingCart)
ElseIf oCart._Items(intCounta)._ShippingX > 0Then
strReq = strReq & "&shipping_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._ShippingX)
If oCart._Items(intCounta)._Shipping2X > 0Then strReq = strReq & "&shipping2_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._Shipping2X)
EndIfEndIfIf oCart._Items(intCounta)._TaxX > 0Then
strReq = strReq & "&tax_"& intItmIdx & "="& FormatPrice(oCart._Items(intCounta)._TaxX)
ElseIf oCart._Items(intCounta)._TaxRateX > 0Then
strReq = strReq & "&tax_rate_"& intItmIdx & "="& FormatBlockPrice(oCart._Items(intCounta)._BlocksX, oCart._Items(intCounta)._QuantityX, oCart._Items(intCounta)._TaxRateX)
EndIfIf oCart._Items(intCounta)._WeightX > 0Then
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"EndIfEndIfIf oCart._Items(intCounta)._OptionFieldsX._Options.Count > 0ThenFor intCountb = 0To oCart._Items(intCounta)._OptionFieldsX._Options.Count - 1
strReq = strReq & "&on"& intCounta & "_"& intCountb & "="& Trim(oCart._Items(intCounta)._OptionFieldsX._Options(intCountb)._Name)
For intCountc = 0To oCart._Items(intCounta)._OptionFieldsX._Options(intCountb)._Suboptions.Count - 1NextNextEndIfNextEndIfElseEndIfElseEndIf
intCounta = Nothing
intCountb = Nothing
intCountc = Nothing
intItmIdx = Nothing
strReq = NothingEndFunctionPrivateFunction FormatBlockPrice(intBlocks AsInteger, intQuantity AsInteger, lngValue AsLong) AsString FormatBlockPrice = "0.00"If intBlocks > 0ThenIf intQuantity > 1Then
FormatBlockPrice = FormatPrice((intQuantity * lngValue) * intBlocks)
ElseIf intQuantity = 1Then
FormatBlockPrice = FormatPrice(lngValue * intBlocks)
EndIfElseIf intQuantity > 1Then
FormatBlockPrice = FormatPrice(intQuantity * lngValue)
ElseIf intQuantity = 1Then
FormatBlockPrice = FormatPrice(lngValue)
EndIfEndIfEndFunctionPrivateFunction FormatPrice(lngValue AsLong) AsString FormatPrice = "0.00"If lngValue > 0Then FormatPrice = FormatNumber(lngValue, 2, TriState.True)
EndFunctionPrivateFunction ObtainEndpointUrl(strAuthentication AsString, strEnvironment AsString, strFormat AsString, ByRef strRtnEndpoint AsString) AsBoolean strRtnEndpoint = ""
ObtainEndpointUrl = FalseSelectCase strAuthentication
Case"apicertificate"If strEnvironment = "live"ThenIf strFormat = "soap"Then
strRtnEndpoint = "https://api.paypal.com/2.0/"Else
strRtnEndpoint = "https://api.paypal.com/nvp"EndIfElseIf strFormat = "soap"Then
strRtnEndpoint = "https://api.sandbox.paypal.com/2.0/"Else
strRtnEndpoint = "https://api.sandbox.paypal.com/nvp"EndIfEndIfCase"adaptiveapis"If strEnvironment = "live"Then
strRtnEndpoint = "https://svcs.paypal.com/AdaptivePayments/API_operation"Else
strRtnEndpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/API_operation"EndIfCase"permissionsapis"If strEnvironment = "live"Then
strRtnEndpoint = "https://svcs.paypal.com/Permission/API_operation"Else
strRtnEndpoint = "https://svcs.sandbox.paypal.com/Permission/API_operation"EndIfCaseElseIf strEnvironment = "live"ThenIf strFormat = "soap"Then
strRtnEndpoint = "https://api-3t.paypal.com/2.0/"Else
strRtnEndpoint = "https://api-3t.paypal.com/nvp"EndIfElseIf strFormat = "soap"Then
strRtnEndpoint = "https://api-3t.sandbox.paypal.com/2.0/"Else
strRtnEndpoint = "https://api-3t.sandbox.paypal.com/nvp"EndIfEndIfEndSelect
ObtainEndpointUrl = (Trim(strRtnEndpoint) <> "")
EndFunction