title: how to simulate payment denial in paypal sandbox
body: <p>I created a sandbox personal account with 0 funds but when I went through the payment in my application against sandbox paypal, it still accepted the payment successfully.  How do I simulate a denial in payment?</p>
  
  <p>NOTE: It keeps reverting to other payment methods instead of using paypal funds.  It has chase manhattan bank and some dicover card setup for some reason in the sandbox account.</p>
  
  <p>code for requesting initial token</p>
  
  <pre><code>    BasicAmountType orderTotal = create(12, false);
  
      AddressType addr = new AddressType();
      addr.setPhone(user.getPhone());
      addr.setName(user.getName());
  
      PaymentDetailsType paymentDetails = new PaymentDetailsType();
      paymentDetails.setPaymentAction(PaymentActionCodeType.fromValue("Sale"));
      paymentDetails.setOrderTotal(orderTotal);
      paymentDetails.setFulfillmentAddress(addr);
  
      List&lt;PaymentDetailsType&gt; paymentDetailsList = new ArrayList&lt;PaymentDetailsType&gt;();
      paymentDetailsList.add(paymentDetails);
  
      SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
  
      Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
      String baseUrl = request.getBase();
      String url = baseUrl+Router.reverse("wizards.Setup.confirm", map).url;
      String url2 = baseUrl+Router.reverse("wizards.Setup.cancelled", map).url;
  
      setExpressCheckoutRequestDetails.setReturnURL(url);
      setExpressCheckoutRequestDetails.setCancelURL(url2);
      setExpressCheckoutRequestDetails.setPaymentDetails(paymentDetailsList);
      setExpressCheckoutRequestDetails.setLocaleCode(getLangCode());
      setExpressCheckoutRequestDetails.setBuyerEmail(user.getEmail());
  
      BillingAgreementDetailsType billingAgreement = new BillingAgreementDetailsType(BillingCodeType.fromValue("RecurringPayments"));
  
      String desc = Messages.get("paypal.product.description");
      billingAgreement.setBillingAgreementDescription(desc);
      List&lt;BillingAgreementDetailsType&gt; billList = new ArrayList&lt;BillingAgreementDetailsType&gt;();
      billList.add(billingAgreement);
      setExpressCheckoutRequestDetails.setBillingAgreementDetails(billList);
  
      SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);
      setExpressCheckoutRequest.setVersion(VERSION);  
      setExpressCheckoutRequest.setErrorLanguage(getLangCode());
  
      SetExpressCheckoutReq setExpressCheckoutReq = new SetExpressCheckoutReq();
      setExpressCheckoutReq.setSetExpressCheckoutRequest(setExpressCheckoutRequest);
  
      Map&lt;String, String&gt; sdkConfig = Utility.getPaypalSdk();
      PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
      try {
          SetExpressCheckoutResponseType response = service.setExpressCheckout(setExpressCheckoutReq);
          AckCodeType ack = response.getAck();
          if(ack == AckCodeType.SUCCESS)
              return response.getToken();
          else if(ack == AckCodeType.SUCCESSWITHWARNING) {
              log.warn("warning on start checkout="+response.getErrors()+", ack="+ack+", token="+response.getToken()+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
              return response.getToken();
          }
  
          throw new RuntimeException("failed to start checkout="+response.getErrors()+", ack="+ack+", token="+response.getToken()+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
  </code></pre>
  
  <p>once paypal redirects back, this is my code to get initial and recurring payment setup</p>
  
  <pre><code>private static CreateRecurringPaymentsProfileResponseDetailsType collectPayment(String token,
          PayPalAPIInterfaceServiceService service, StoreEmployeeDbo emp)
          throws Exception {
      BasicAmountType amount = create(PRICE, true);
      ActivationDetailsType activationDetails = new ActivationDetailsType();
      activationDetails.setFailedInitialAmountAction(FailedPaymentActionType.CANCELONFAILURE);
      activationDetails.setInitialAmount(amount);
  
      BasicAmountType periodAmt = create(PRICE, false);
      BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType();
      paymentPeriod.setAmount(periodAmt);
      paymentPeriod.setBillingFrequency(1);
      paymentPeriod.setBillingPeriod(BillingPeriodType.MONTH);
  
      String desc = Messages.get("paypal.product.description");
      ScheduleDetailsType scheduleDetails = new ScheduleDetailsType(desc, paymentPeriod);
      scheduleDetails.setActivationDetails(activationDetails);
      scheduleDetails.setMaxFailedPayments(3);
  
      DateTime dt = new DateTime();
      DateTime plusMonths = dt.plusMonths(1);
      String dateStr = ""+plusMonths;
      RecurringPaymentsProfileDetailsType recurringDetails = new RecurringPaymentsProfileDetailsType();
      recurringDetails.setBillingStartDate(dateStr);
      recurringDetails.setSubscriberName(emp.getName());
  
      CreateRecurringPaymentsProfileRequestDetailsType profileReq = new CreateRecurringPaymentsProfileRequestDetailsType();
      profileReq.setToken(token);
      profileReq.setScheduleDetails(scheduleDetails);
      profileReq.setRecurringPaymentsProfileDetails(recurringDetails);
  
      CreateRecurringPaymentsProfileRequestType reqType = new CreateRecurringPaymentsProfileRequestType();
      reqType.setVersion(VERSION);
      reqType.setErrorLanguage(getLangCode());
      reqType.setCreateRecurringPaymentsProfileRequestDetails(profileReq);
  
      CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq();
      req.setCreateRecurringPaymentsProfileRequest(reqType);
      CreateRecurringPaymentsProfileResponseType response = service.createRecurringPaymentsProfile(req );
  
      AckCodeType ack = response.getAck();
      if(ack == AckCodeType.SUCCESSWITHWARNING) {
          log.warn("warning on start checkout="+response.getErrors()+", ack="+ack+", version="+response.getVersion()+" corrId="+response.getCorrelationID());             
          if(response.getCreateRecurringPaymentsProfileResponseDetails() != null) {
              CreateRecurringPaymentsProfileResponseDetailsType details = response.getCreateRecurringPaymentsProfileResponseDetails();
              log.warn("more info.  profileid="+details.getProfileID()+" txid="+details.getTransactionID()+" status="+details.getProfileStatus().getValue());
          }
          return response.getCreateRecurringPaymentsProfileResponseDetails();
      } else if(ack == AckCodeType.SUCCESS) {
          return response.getCreateRecurringPaymentsProfileResponseDetails();
      }
  
      throw new RuntimeException("failure collecting payment="+response.getErrors()+", ack="+ack+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
  }
  </code></pre>
  
  <p>yet this was succeeding.</p>
  
  <p>EDIT: I turned on negative testing and when I request the paypal token, I set the amount to 105.37 (I tried USD and HKD but neither helps)....</p>
  
  <pre><code>            //In this code, t7he orderTotal is 105.37 in USD (this is part of the request payment token code
      PaymentDetailsType paymentDetails = new PaymentDetailsType();
      paymentDetails.setPaymentAction(PaymentActionCodeType.fromValue("Sale"));
      paymentDetails.setOrderTotal(orderTotal);
      paymentDetails.setFulfillmentAddress(addr);
  </code></pre>
  
  <p>Then when user clicks purchase, I set up the recurring profile and insert 105.37 into the intial amount AND the recurring amount in the following code.....</p>
  
  <pre><code>            //amount variable AND periodAmt variable are setup with 105.37 in USD
      ActivationDetailsType activationDetails = new ActivationDetailsType();
      activationDetails.setFailedInitialAmountAction(FailedPaymentActionType.CANCELONFAILURE);
      activationDetails.setInitialAmount(amount);
  
      BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType();
      paymentPeriod.setAmount(periodAmt);
      paymentPeriod.setBillingFrequency(1);
      paymentPeriod.setBillingPeriod(BillingPeriodType.MONTH);
  </code></pre>
  
  <p>The payment still succeeds just fine :(</p>
  
  <p>The soap message sent from above is </p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" 
  xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes"&gt;
  &lt;soapenv:Header&gt;&lt;ns:RequesterCredentials&gt;&lt;ebl:Credentials&gt;&lt;ebl:Username&gt;dean-facilitator_api1.xsoftware.biz&lt;/ebl:Username&gt;
  &lt;ebl:Password&gt;138807XXXX&lt;/ebl:Password&gt;    
  &lt;ebl:Signature&gt;AY.QZJbiiP6AK3cWhljHCEhQtTyzApzADFFNYBR&lt;/ebl:Signature&gt;&lt;/ebl:Credentials&gt;
  &lt;/ns:RequesterCredentials&gt;&lt;/soapenv:Header&gt;&lt;soapenv:Body&gt;   
  &lt;ns:CreateRecurringPaymentsProfileReq&gt;&lt;ns:CreateRecurringPaymentsProfileRequest&gt;
  &lt;ebl:ErrorLanguage&gt;zh_CN&lt;/ebl:ErrorLanguage&gt;&lt;ebl:Version&gt;104.0&lt;/ebl:Version&gt;
  &lt;ebl:CreateRecurringPaymentsProfileRequestDetails&gt;
  &lt;ebl:Token&gt;EC-0KU028910G908352C&lt;/ebl:Token&gt;
  &lt;ebl:RecurringPaymentsProfileDetails&gt;&lt;ebl:SubscriberName&gt;wert&lt;/ebl:SubscriberName&gt;&lt;ebl:BillingStartDate&gt;2014-01-29T12:06:17.004-07:00&lt;/ebl:BillingStartDate&gt;&lt;/ebl:RecurringPaymentsProfileDetails&gt;&lt;ebl:ScheduleDetails&gt;
  &lt;ebl:Description&gt;You will be billed monthly while your store is online and live.  You can cancel and close your store at any time.&lt;/ebl:Description&gt;&lt;ebl:PaymentPeriod&gt;&lt;ebl:BillingPeriod&gt;Month&lt;/ebl:BillingPeriod&gt;
  &lt;ebl:BillingFrequency&gt;1&lt;/ebl:BillingFrequency&gt;&lt;ebl:Amount currencyID="USD"&gt;105.37&lt;/ebl:Amount&gt;&lt;/ebl:PaymentPeriod&gt;
  &lt;ebl:MaxFailedPayments&gt;3&lt;/ebl:MaxFailedPayments&gt;
  &lt;ebl:ActivationDetails&gt;&lt;ebl:InitialAmount currencyID="USD"&gt;105.37&lt;/ebl:InitialAmount&gt;
  &lt;ebl:FailedInitialAmountAction&gt;CancelOnFailure&lt;/ebl:FailedInitialAmountAction&gt;
  &lt;/ebl:ActivationDetails&gt;&lt;/ebl:ScheduleDetails&gt;
  &lt;/ebl:CreateRecurringPaymentsProfileRequestDetails&gt;
  &lt;/ns:CreateRecurringPaymentsProfileRequest&gt;&lt;/ns:CreateRecurringPaymentsProfileReq&gt;
  </code></pre>
  
  <p></p>
  
  <p>thanks,
  Dean</p>