Search code examples
phpiosbraintree

How to update credit card information on braintree server php iOS?


I am using braintree SDK for payments. I have successfully integrated payment methods and transactions. But now I am stuck in updating the credit information if user decides to use their other card instead of the old one.

To achieve this I have made a web service which gets cardholder name, cc no, expiration month and year and cvv.


Solution

  • You can create the credit card by submitting all the details like this:

    result = Braintree_CreditCard::create([
        'cardholder_name' => 'John Doe',
        'cvv' => '123',
        'expiration_date' => '12/2019,
        'number' => '4111111111111111',
        'options' => [
            'verify_card' => True
        ]
    ])
    # use this credit card token(5mk3f2).
    print(result.credit_card.token)
    
    We this credit card token to update the credit card by as follows:
    
    $result = Braintree_PaymentMethod::update(
      '5mk3f2',
      [
          'cardholder_name' => 'Doe Jhon',
          'cvv' => 'XXX',
          'expiration_date' => '8/2020,
          'number' => '4111111111111118',
          'billingAddress' => [
              'streetAddress' => '100 Maple Lane',
              'options' => [
                'updateExisting' => true
              ]
         ]
     ]);