1. function TfrmSignup.CreateSubscription: boolean;
  2. var
  3.   auth: TAuthorizeNetARB;
  4.   yy, mm, dd: word;
  5. begin
  6.   CoInitialize(nil);
  7.   Result := false;
  8.   DecodeDate(Now, yy, mm, dd);
  9.   auth := TAuthorizeNetARB.Create;
  10.   try
  11.     with auth do
  12.     begin
  13.       AUTHORIZE_LOGIN := _AUTHORIZE_LOGIN_live;
  14.       AUTHORIZE_KEY := _AUTHORIZE_KEY_live;
  15.       Merchant_assigned_name := IntToStr(FUserID);
  16.       Amount := ReadValuesForAccoutType(cbAccountType.ItemIndex, 'AmountCharged');
  17.       Trialamount := ReadValuesForAccoutType(cbAccountType.ItemIndex, 'TrialAmountCharged');
  18.       Interval_length := StrToIntDef(ReadValuesForAccoutType(cbAccountType.ItemIndex, 'IntervalMonts'), 1); // months
  19.       Startdate_month := mm;
  20.       Startdate_day := dd;
  21.       Startdate_year := yy;
  22.       TotalOccurrences := StrToIntDef(ReadValuesForAccoutType(cbAccountType.ItemIndex, 'ContractMonths'), 9999);
  23.       TrialOccurrences := StrToIntDef(ReadValuesForAccoutType(cbAccountType.ItemIndex, 'TrialOccurrences'), 0);
  24.       CreditCard_cardNumber := ReplaceBadChars(eCardNumber.Text);
  25.       CreditCard_expirationDate := ReplaceBadChars(eCardExpire.Text); // yyyy-mm
  26.       CreditCard_cardCode := Trim(eCardCode.Text);
  27.       CustomerID := IntToStr(FUserID);
  28.       CustomerEmail := Trim(dbeEmail.Text);
  29.       CustomerPhone := Trim(dbeCCode.Text) + Trim(dbeACode.Text) + Trim(dbePhone.Text);
  30.       CustomerFax := Trim(dbeFax.Text);
  31.       BillTo_firstName := Trim(dbeFname.Text);
  32.       BillTo_lastName := Trim(dbeLname.Text);
  33.       BillTo_address := Trim(dbeAddress1.Text) + ' ' + Trim(dbeAddress2.Text);
  34.       BillTo_city := Trim(dbeCity.Text);
  35.       BillTo_state := cbState.Items[cbState.ItemIndex];
  36.       BillTo_zip := Trim(dbeZip.Text);
  37.       BillTo_country := cbCountry.Items[cbCountry.ItemIndex];
  38.       MakePayment;
  39.       if ReturnCode = 0 then // success
  40.       begin
  41.         Result := true;
  42.         FReturedSubscriptioID := ReturnSubscriptionID;
  43.         FReturedText := ReturnMessage;
  44.       end
  45.       else
  46.       begin
  47.         Result := false;
  48.         FReturedText := ReturnMessage;
  49.       end;
  50.     end;
  51.   finally
  52.     auth.Free;
  53.     CoUninitialize;
  54.   end;
  55. end;