Worldpay / worldpay-lib-php

PHP Library for Worldpay REST API
https://online.worldpay.com
MIT License
43 stars 32 forks source link

Create token function #17

Open valetzyzy opened 7 years ago

valetzyzy commented 7 years ago

Please implement createToken function according to this link documentation

trevski commented 6 years ago

+1

trevski commented 6 years ago

I think this is already in place... but it does not seem to work.

    Dim oTokenRequest = New WorldPay.Sdk.Models.TokenRequest() With {
                                .clientKey = _ServiceKey,
                                .paymentMethod = paymentMethod,
                                .reusable = True
                            }

                            Dim authSvc As AuthService = wpClient.GetAuthService()

                            tokenResponse = authSvc.GetToken(oTokenRequest)

I needed to add the tokenURL to the appsettings

<appSettings>
  <add key="TokenUrl" value="https://api.worldpay.com/v1/tokens" />

But I am getting

System.Net.WebException: Error with request https://api.worldpay.com/v1/tokens ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed because the remote party has closed the transport stream. at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at Worldpay.Sdk.Http.CreateRequest(String api, RequestMethod method, Object data, Boolean authorize) in D:\HostingSpaces_objSource\ReferencedAssemblies\worldpay-lib-dotnet-master\worldpay-lib-dotnet-4-6\Worldpay.Sdk\Http.cs:line 167 --- End of inner exception stack trace --- at Worldpay.Sdk.Http.CreateRequest(String api, RequestMethod method, Object data, Boolean authorize) in D:\HostingSpaces_objSource\ReferencedAssemblies\worldpay-lib-dotnet-master\worldpay-lib-dotnet-4-6\Worldpay.Sdk\Http.cs:line 175 at Worldpay.Sdk.Http.Post[TI,TO](String api, TI item) in D:\HostingSpaces_objSource\ReferencedAssemblies\worldpay-lib-dotnet-master\worldpay-lib-dotnet-4-6\Worldpay.Sdk\Http.cs:line 87 at Worldpay.Sdk.AuthService.GetToken(TokenRequest tokenRequest) in D:\HostingSpaces_objSource\ReferencedAssemblies\worldpay-lib-dotnet-master\worldpay-lib-dotnet-4-6\Worldpay.Sdk\AuthService.cs:line 18