예제 #1
0
  private static NVPDecoder sendNVPRequest(GenericValue payPalConfig, NVPEncoder encoder)
      throws PayPalException {
    NVPCallerServices caller = new NVPCallerServices();
    try {
      APIProfile profile = ProfileFactory.createSignatureAPIProfile();
      profile.setAPIUsername(payPalConfig.getString("apiUserName"));
      profile.setAPIPassword(payPalConfig.getString("apiPassword"));
      profile.setSignature(payPalConfig.getString("apiSignature"));
      profile.setEnvironment(payPalConfig.getString("apiEnvironment"));
      caller.setAPIProfile(profile);
    } catch (PayPalException e) {
      Debug.logError(e.getMessage(), module);
    }

    String requestMessage = encoder.encode();
    String responseMessage = caller.call(requestMessage);

    NVPDecoder decoder = new NVPDecoder();
    decoder.decode(responseMessage);
    if (!"Success".equals(decoder.get("ACK"))) {
      Debug.logError(
          "A response other than success was received from PayPal: " + responseMessage, module);
    }

    return decoder;
  }
예제 #2
0
  public String ReauthorizationCode(String authorizationId, String amount, String currencyCode) {

    NVPCallerServices caller = null;
    NVPEncoder encoder = new NVPEncoder();
    NVPDecoder decoder = new NVPDecoder();

    try {
      caller = new NVPCallerServices();
      APIProfile profile = ProfileFactory.createSignatureAPIProfile();
      /*
      WARNING: Do not embed plaintext credentials in your application code.
      Doing so is insecure and against best practices.
      Your API credentials must be handled securely. Please consider
      encrypting them for use in any production environment, and ensure
      that only authorized individuals may view or modify them.
      */

      // Set up your API credentials, PayPal end point, API operation and version.
      profile.setAPIUsername("sdk-three_api1.sdk.com");
      profile.setAPIPassword("QFZCWN5HZM8VBG7Q");
      profile.setSignature("AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ");
      profile.setEnvironment("sandbox");
      profile.setSubject("");
      caller.setAPIProfile(profile);
      encoder.add("VERSION", "51.0");
      encoder.add("METHOD", "DoReauthorization");

      // Add request-specific fields to the request string.
      encoder.add("AuthorizationID", authorizationId);
      encoder.add("AMT", amount);
      encoder.add("CURRENCYCODE", currencyCode);

      // Execute the API operation and obtain the response.
      String NVPRequest = encoder.encode();
      String NVPResponse = caller.call(NVPRequest);
      decoder.decode(NVPResponse);

    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return decoder.get("ACK");
  }