package com.stripe.example.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import com.stripe.example.PaymentForm;
import com.stripe.example.R;
import com.stripe.example.activity.PaymentActivity;

public class PaymentFormFragment extends Fragment implements PaymentForm {

    Button saveButton;
    EditText cardNumber;
    EditText cvc;
    Spinner monthSpinner;
    Spinner yearSpinner;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.payment_form_fragment, container, false);

        this.saveButton = (Button) view.findViewById(R.id.save);
        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                saveForm(view);
            }
        });

        this.cardNumber = (EditText) view.findViewById(R.id.number);
        this.cvc = (EditText) view.findViewById(R.id.cvc);
        this.monthSpinner = (Spinner) view.findViewById(R.id.expMonth);
        this.yearSpinner = (Spinner) view.findViewById(R.id.expYear);

        return view;
    }

    @Override
    public String getCardNumber() {
        return this.cardNumber.getText().toString();
    }

    @Override
    public String getCvc() {
        return this.cvc.getText().toString();
    }

    @Override
    public Integer getExpMonth() {
        return Integer.parseInt(this.monthSpinner.getSelectedItem().toString());
    }

    @Override
    public Integer getExpYear() {
        return Integer.parseInt(this.yearSpinner.getSelectedItem().toString());
    }

    public void saveForm(View button) {
        ((PaymentActivity)getActivity()).saveCreditCard(this);
    }
}

@@ -1632,32 +1632,26 @@
  return 
+get
 Integer
-.parseInt
 (this.mo
@@ -1664,37 +1664,8 @@
 nner
-.getSelectedItem().toString()
 );%0A 
@@ -1737,24 +1737,18 @@
 urn 
+get
 Integer
-.parseInt
 (thi
@@ -1764,37 +1764,8 @@
 nner
-.getSelectedItem().toString()
 );%0A 
@@ -1878,11 +1878,212 @@
 );%0A    %7D
+%0A%0A    private Integer getInteger(Spinner spinner) %7B%0A    %09try %7B%0A    %09%09return Integer.parseInt(spinner.getSelectedItem().toString());%0A    %09%7D catch (NumberFormatException e) %7B%0A    %09%09return 0;%0A    %09%7D%0A    %7D
 %0A%7D%0A

Fix crash when month or year spinner was left as default