title: Updating and Deleting Payment Methods with Acumatica API
body: <p>Thanks to the post on <a href="https://stackoverflow.com/questions/26683250/acumatica-creating-customer-payment-method-with-api">Creating customer payment method with api</a> I am able to create a new Payment Method successfully using the API.  But I can't figure out how to update or delete an existing payment method.  There doesn't seem to be any type of key field.  I've updated and deleted Contacts and Locations with the API, but Contacts have Contact IDs, and Locations have LocationIDs.  There doesn't seem to be a PaymentMethodID.  I thought maybe the "Card/Account No." field might function as that, but I wasn't able to make that work.  And I've noticed that I can save two Payment Methods with identical card numbers, so that would make identical keys if that field was used anyway.</p>
  
  <p>Here's the code I tried for updating.  It's mostly Chris's code from the other post I linked to, but trying to add an extra key field for the update.</p>
  
  <pre><code>Public Function UpdateCreditCard(ByVal customerID As String, ByVal existingAcctNum As String, ByVal paymentMethodCode As String, ByVal CCNum As String, ByVal expiration As String, ByVal nameOnCard As String, ByVal active As Boolean)
      Dim paymentMethod As AR303010Content = m_context.AR303010GetSchema()
      m_context.AR303010Clear()
  
      ' main level fields
      Dim customerVal As Value = CreateValue(paymentMethod.PaymentMethodSelection.Customer, customerID)
      Dim paymentMethodCodeVal As Value = CreateValue(paymentMethod.PaymentMethodSelection.PaymentMethod, paymentMethodCode)
  
      ' inner level fields
      Dim ccNumName As Value = CreateValue(paymentMethod.PaymentMethodDetails.Description, "CCDNUM")
      Dim ccNumValue As Value = CreateValue(paymentMethod.PaymentMethodDetails.Value, CCNum, True)
  
      Dim ccExpName As Value = CreateValue(paymentMethod.PaymentMethodDetails.Description, "EXPDATE")
      Dim ccExpValue As Value = CreateValue(paymentMethod.PaymentMethodDetails.Value, expiration, True)
  
      Dim ccNameName As Value = CreateValue(paymentMethod.PaymentMethodDetails.Description, "NAMEONCC")
      Dim ccNameValue As Value = CreateValue(paymentMethod.PaymentMethodDetails.Value, nameOnCard, True)
  
      Dim saveCommands() As Command
      If existingAcctNum = "" Then
          ' new credit card
          saveCommands = {customerVal, paymentMethod.Actions.Insert, paymentMethodCodeVal, ccNumName, ccNumValue, ccExpName, ccExpValue, ccNameName, ccNameValue, paymentMethod.Actions.Save}
      Else
          ' existing credit card, only allow update of Active or expiration based on "description"
          Dim descriptionVal As Value = CreateValue(paymentMethod.PaymentMethodDetails.Description, existingAcctNum)
          Dim activeVal As Value = CreateValue(paymentMethod.PaymentMethodSelection.Active, active.ToString())
          saveCommands = {customerVal, descriptionVal, ccExpName, ccExpValue, activeVal, paymentMethod.Actions.Save}
      End If
      Dim updateResult As AR303010Content() = m_context.AR303010Submit(saveCommands)
  
      Return ""
  End Function
  </code></pre>
  
  <p>Another confusing part of this is that the two fields I would really like to let the user update are either the expiration date, or whether the card is Active.  But the Active flag is one of the fields in the list accessible from the Customer screen, and the expiration date is a field only accessible from the Payment Method screen.  If those are two different API calls, then will I need a different key field in each one of them?</p>