private void cancelUnclaimedPayout(string itemID, PayPalSession payPalSession) { try { var request = new WebClient.RequestParams { Caller = this, Uri = new Uri(m_ApiUri + URI_CANCEL_UNCLAIMED_PAYOUT.Args(itemID)), Method = HTTPRequestMethod.POST, ContentType = ContentType.JSON, Headers = new Dictionary <string, string> { { HDR_AUTHORIZATION, HDR_AUTHORIZATION_OAUTH.Args(payPalSession.AuthorizationToken.AccessToken) }, } }; var response = WebClient.GetJson(request); Log(MessageType.Info, "cancelUnclaimedPayout()", response.ToJSON()); } catch (Exception ex) { var message = StringConsts.PAYPAL_PAYOUT_CANCEL_ERROR.Args(ex.ToMessageWithType()); var error = PayPalPaymentException.ComposeError(message, ex); Log(MessageType.Error, "cancelUnclaimedPayout()", error.Message, ex); throw error; } }
private Transaction doTransfer(PaySession session, ITransactionContext context, Account from, Account to, Amount amount, string description = null, object extraData = null) { var id = Log(MessageType.Info, "doTransfer()", StringConsts.PAYPAL_PAYOUT_MESSAGE.Args(to, amount)); try { var payPalSession = session as PayPalSession; var actualAccountData = PaySystemHost.AccountToActualData(context, to); var request = new WebClient.RequestParams { Caller = this, Uri = new Uri(m_ApiUri + URI_PAYOUTS), QueryParameters = new Dictionary <string, string> { { PRM_SYNC_MODE, m_SyncMode.AsString() } }, Method = HTTPRequestMethod.POST, ContentType = ContentType.JSON, Headers = new Dictionary <string, string> { { HDR_AUTHORIZATION, HDR_AUTHORIZATION_OAUTH.Args(payPalSession.AuthorizationToken.AccessToken) }, }, Body = getPayoutJSONBody(actualAccountData, amount, description) }; var response = WebClient.GetJson(request); Log(MessageType.Info, "doTransfer()", response.ToJSON(), null, id); checkPayoutStatus(response, payPalSession); var transaction = createPayoutTransaction(session, context, response, to, amount, description); StatTransfer(amount); return(transaction); } catch (Exception ex) { StatTransferError(); var message = StringConsts.PAYPAL_PAYOUT_ERROR.Args(to, amount, ex.ToMessageWithType()); var error = PayPalPaymentException.ComposeError(message, ex); Log(MessageType.Error, "doTransfer()", error.Message, ex, id); throw error; } }
private void refreshOAuthToken(PayPalConnectionParameters connectParameters) { try { Log(MessageType.Info, "refreshOAuthToken()", StringConsts.PAYPAL_REFRESH_TOKEN_MESSAGE); var user = connectParameters.User; var request = new WebClient.RequestParams { Caller = this, Uri = new Uri(m_ApiUri + URI_GET_OAUTH_TOKEN), Method = HTTPRequestMethod.POST, ContentType = ContentType.FORM_URL_ENCODED, Headers = new Dictionary <string, string> { { HDR_AUTHORIZATION, HDR_AUTHORIZATION_BASIC.Args(getBaseAuthString(user.Credentials)) } }, BodyParameters = new Dictionary <string, string> { { PRM_GRANT_TYPE, PRM_CLIENT_CREDENTIALS } } }; var response = WebClient.GetJson(request); Log(MessageType.Info, "refreshOAuthToken()", response.ToJSON()); var oauthToken = new PayPalOAuthToken(response, m_OAuthTokenExpirationMargin); var token = new AuthenticationToken(PAYPAL_REALM, oauthToken); connectParameters.User = new User(user.Credentials, token, user.Name, user.Rights); Log(MessageType.Info, "refreshOAuthToken()", StringConsts.PAYPAL_TOKEN_REFRESHED_MESSAGE); } catch (Exception ex) { var message = StringConsts.PAYPAL_REFRESH_TOKEN_ERROR.Args(ex.ToMessageWithType()); var error = PayPalPaymentException.ComposeError(message, ex); Log(MessageType.Error, "refreshOAuthToken()", error.Message, ex); throw error; } }