1

I have developed in the past in VB.net and I simply can't figure out how to properly call this function and how to get the response so I can display it on a web page response.

I translated the example c# code to VB. Here is my code behind for an aspx page that I wish to use to make the request and then display the response in my page:

Imports OffAmazonPaymentsService
Imports OffAmazonPaymentsService.Model

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Write(GetOrderReferenceDetails(???service???, "asdfsadf", "asdfsadf", "asdfasdf"))

    End Sub
    Private Shared Function GetOrderReferenceDetails(service As IOffAmazonPaymentsService, sellerId As String, amazonOrderReferenceId As String, addressConsentToken As String) As GetOrderReferenceDetailsResponse
        ' Required parameters
        Dim request As New GetOrderReferenceDetailsRequest()
        request.SellerId = sellerId
        request.AmazonOrderReferenceId = amazonOrderReferenceId

        ' Optional parameters
        request.AddressConsentToken = addressConsentToken

        Return service.GetOrderReferenceDetails(request)
    End Function
End Class

I don't know how to call that function's first (service) parameter and to then display the contents of the response.

Let me know if my question is not clear enough. here is the example they gave in c sharp format....

using OffAmazonPaymentsService;
using OffAmazonPaymentsService.Model;

public class GetOrderReferenceDetailsSample
{
    /**
     * Sample GetOrderReferenceDetails method that takes generic inputs, constructs a request object,
     * and make a call to the service.
     */
    private static GetOrderReferenceDetailsResponse GetOrderReferenceDetails(
        IOffAmazonPaymentsService service,
        string sellerId,
        string amazonOrderReferenceId,
        string addressConsentToken)
    {
        // Required parameters
        GetOrderReferenceDetailsRequest request = new GetOrderReferenceDetailsRequest();
        request.SellerId = sellerId;
        request.AmazonOrderReferenceId = amazonOrderReferenceId;

        // Optional parameters
        request.AddressConsentToken = addressConsentToken;

        return service.GetOrderReferenceDetails(request);
    }
}
T.S.
  • 18,195
  • 11
  • 58
  • 78
  • You need to pass an object of a type that implements `IOffAmazonPaymentsService`; does your project include such a class? – Tieson T. Nov 30 '15 at 04:14
  • @TiesonT. -thank you.. yes I have the OffAmazonPaymentsService DLL added as a reference in my project and the references are being recognized. I think you are right about the object call.. I just can't figure out the correct format or syntax to make the call properly. – Tracey Paul Smith Nov 30 '15 at 04:30
  • To be clear .. it's the ???service??? portion i don't know how to format or use... I know how to pass the other parameters for the function.. I have used/built funciton in vb.net before.. but the service paramater is confusing me. – Tracey Paul Smith Nov 30 '15 at 04:33
  • It's unlikely that the service is static/shared, so you need to new up an instance and then pass it in. Are you using the AWS SDK? – Tieson T. Nov 30 '15 at 04:33
  • Assuming you are using the AWS SDK, the [sample console app](https://github.com/amzn/login-and-pay-with-amazon-sdk-csharp/blob/d2e075c322664044d27a3b4f5fbef6919aeb7d8d/src/OffAmazonPaymentsServiceSampleLibrary/OffAmazonPaymentsServiceSampleLibrary/OffAmazonPaymentsServiceSamples.cs) shows how to instantiate an instance of the service class. – Tieson T. Nov 30 '15 at 04:52
  • @TiesonT.- thanks again for trying to help me... no I am not trying to use that code base.. but instead to take some very direct, specific api call examples they have for someone with an amazon seller central login and pay seller account. That is the code base I would use, but the examples they have, in what is called the "integration scratchpad for login and pay" is more specific, less difficult to muddle through then the .net sdk you found. If I can figure out the syntax, for calling the funciton.. I will be fine. Here is c sharp code example exactly as they give it on the scratchpad site: – Tracey Paul Smith Nov 30 '15 at 04:52
  • ok.. so i can't paste the example code into this comment area - to small... but I think your last comment about sample console app code makes it clear.. the example they gave me doesn't have this part demonstrated in that sample console app of creating the service config instantiaion and then the service instantiation and then I need to set the proper request parameters for whichever api call I am attempting. Sound right? – Tracey Paul Smith Nov 30 '15 at 05:07
  • Yes, comments are not intended for code blocks. If it's relevant to your question, edit the question to include it (the edit button is below the tag list). The example code you're working from may assume some sort of DI container and/or global instance is used, but without seeing the example I'm guessing. So, if I'm parsing your comment correctly, yes, you just need to translate line 100 in the sample I linked to VB, and then pass that variable in for the first parameter in your function. – Tieson T. Nov 30 '15 at 05:11
  • thanks I didn't see the edit link.. very tiny - they should improve that... ; ) – Tracey Paul Smith Nov 30 '15 at 05:21
  • I would assume this sample is invoked by another chunk of code that supplies the relevant arguments; is this from a publicly available codebase that I can verify my assumptions against (to give more than wild guesses)? – Tieson T. Nov 30 '15 at 05:27

1 Answers1

0

Disclaimer: my VB is "rusty" so debug and improve as necessary

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        Dim props As OffAmazonPaymentsServicePropertyCollection = OffAmazonPaymentsServicePropertyCollection.getInstance()
        Dim client As New OffAmazonPaymentsServiceClient(props)
        Dim result as GetOrderReferenceDetailsResponse = GetAmzOrderRef(client, props, "oref", "token")

End Sub


Private Shared Function GetAmzOrderRef(service As IOffAmazonPaymentsService, props As OffAmazonPaymentsServicePropertyCollection, amazonOrderReferenceId As String, addressConsentToken As String) As GetOrderReferenceDetailsResponse

        Dim request as New GetOrderReferenceDetailsRequest()
        With request
            .SellerId = props.MerchantID
            .AmazonOrderReferenceId = amazonOrderReferenceId
            .AddressConsentToken = addressConsentToken
        End With
        Return service.GetOrderReferenceDetails(request)

End Function

Notes:

  • you should have your config values set (web.config or app.config as necessary), that's where OffAmazonPaymentsServicePropertyCollection.getInstance() will obtain values

  • the above sample code will fail (as expected) because of dummy values for reference id and token, but that "error" is from the Amazon API (already) - e.g. response error "invalid reference id" or "invalid token" etc....

Hth....

EdSF
  • 11,753
  • 6
  • 42
  • 83