unit authorizenetsoapcall;
interface
uses Classes, SysUtils, AuthService, XSBuiltIns;
type
TAuthorizeNetARB = class(TObject)
private
FMerc: MerchantAuthenticationType;
FArb: ARBSubscriptionType;
FRet: ARBCreateSubscriptionResponseType;
FAUTHORIZE_LOGIN: string;
FAUTHORIZE_KEY: string;
FMerchant_assigned_name: string;
FAmount: string;
FTrialamount: string;
FInterval_length: SmallInt;
FStartdate_month: Word;
FStartdate_day: Word;
FStartdate_year: integer;
FTotalOccurrences: SmallInt;
FTrialOccurrences: SmallInt;
FCreditCard_cardNumber: string;
FCreditCard_expirationDate: string;
FCreditCard_cardCode: string;
FCustomerID: string;
FCustomerEmail: string;
FCustomerPhone: string;
FCustomerFax: string;
FBillTo_firstName: string;
FBillTo_lastName: string;
FBillTo_address: string;
FBillTo_city: string;
FBillTo_state: string;
FBillTo_zip: string;
FBillTo_country: string;
// returns
FReturnCode: integer;
FReturnMessage: string;
FReturnSubscriptionID: string;
procedure InitSOAP;
public
constructor Create;
destructor Destroy; override;
function MakePayment: string;
published
property AUTHORIZE_LOGIN: string read FAUTHORIZE_LOGIN write FAUTHORIZE_LOGIN;
property AUTHORIZE_KEY: string read FAUTHORIZE_KEY write FAUTHORIZE_KEY;
property Merchant_assigned_name: string read FMerchant_assigned_name write FMerchant_assigned_name;
property Amount: string read FAmount write FAmount;
property Trialamount: string read FTrialamount write FTrialamount;
property Interval_length: SmallInt read FInterval_length write FInterval_length;
property Startdate_month: Word read FStartdate_month write FStartdate_month;
property Startdate_day: Word read FStartdate_day write FStartdate_day;
property Startdate_year: integer read FStartdate_year write FStartdate_year;
property TotalOccurrences: SmallInt read FTotalOccurrences write FTotalOccurrences;
property TrialOccurrences: SmallInt read FTrialOccurrences write FTrialOccurrences;
property CreditCard_cardNumber: string read FCreditCard_cardNumber write FCreditCard_cardNumber;
property CreditCard_expirationDate: string read FCreditCard_expirationDate write FCreditCard_expirationDate;
property CreditCard_cardCode: string read FCreditCard_cardCode write FCreditCard_cardCode;
property CustomerID: string read FCustomerID write FCustomerID;
property CustomerEmail: string read FCustomerEmail write FCustomerEmail;
property CustomerPhone: string read FCustomerPhone write FCustomerPhone;
property CustomerFax: string read FCustomerFax write FCustomerFax;
property BillTo_firstName: string read FBillTo_firstName write FBillTo_firstName;
property BillTo_lastName: string read FBillTo_lastName write FBillTo_lastName;
property BillTo_address: string read FBillTo_address write FBillTo_address;
property BillTo_city: string read FBillTo_city write FBillTo_city;
property BillTo_state: string read FBillTo_state write FBillTo_state;
property BillTo_zip: string read FBillTo_zip write FBillTo_zip;
property BillTo_country: string read FBillTo_country write FBillTo_country;
property ReturnCode: integer read FReturnCode;
property ReturnMessage: string read FReturnMessage;
property ReturnSubscriptionID: string read FReturnSubscriptionID;
end;
implementation
{ TAuthorizeNetARB }
constructor TAuthorizeNetARB.Create;
begin
FMerc := MerchantAuthenticationType.Create;
FArb := ARBSubscriptionType.Create;
end;
destructor TAuthorizeNetARB.Destroy;
begin
FMerc.Free;
FArb.Free;
FRet.Free;
inherited;
end;
procedure TAuthorizeNetARB.InitSOAP;
var
amount: TxsDecimal;
trialamount: TxsDecimal;
startdate: TXSDate;
begin
amount := TxsDecimal.Create;
trialamount := TxsDecimal.Create;
startdate := TXSDate.Create;
FMerc.name_ := AUTHORIZE_LOGIN;
FMerc.transactionKey := AUTHORIZE_KEY;
FArb.name_ := FMerchant_assigned_name;
amount.DecimalString := FAmount;
FArb.amount := amount;
trialamount.DecimalString := FTrialamount;
FArb.trialAmount := trialamount;
FArb.paymentSchedule := PaymentScheduleType.Create;
FArb.paymentSchedule.interval := PaymentScheduleTypeInterval.Create;
FArb.paymentSchedule.interval.length := Interval_length;
FArb.paymentSchedule.interval.unit_ := ARBSubscriptionUnitEnum.months;
startdate.Month := Startdate_month;
startdate.Day := Startdate_day;
startdate.Year := Startdate_year;
FArb.paymentSchedule.startDate := startdate;
FArb.paymentSchedule.totalOccurrences := TotalOccurrences;
FArb.paymentSchedule.trialOccurrences := TrialOccurrences;
FArb.payment := PaymentType.Create;
FArb.payment.creditCard := CreditCardType.Create;
FArb.payment.creditCard.cardNumber := CreditCard_cardNumber;
FArb.payment.creditCard.expirationDate := CreditCard_expirationDate;
FArb.payment.creditCard.cardCode := CreditCard_cardCode;
FArb.customer := CustomerType.Create;
FArb.customer.id := FCustomerID;
FArb.customer.email := FCustomerEmail;
FArb.customer.phoneNumber := FCustomerPhone;
FArb.customer.faxNumber := FCustomerFax;
FArb.billTo := NameAndAddressType.Create;
FArb.billTo.firstName := BillTo_firstName;
FArb.billTo.lastName := BillTo_lastName;
FArb.billTo.address := BillTo_address;
FArb.billTo.city := BillTo_city;
FArb.billTo.state := BillTo_state;
FArb.billTo.zip := BillTo_zip;
FArb.billTo.country := BillTo_country;
end;
// make payment will return 0 as ReturnCode if the subscription is successfull
function TAuthorizeNetARB.MakePayment: string;
begin
result := '';
try
InitSOAP;
FRet := GetServiceSoap.ARBCreateSubscription(FMerc, FArb);
FReturnCode := integer(FRet.resultCode);
FReturnMessage := FRet.messages[0].text;
FReturnSubscriptionID := IntToStr(FRet.subscriptionId);
except
on e: Exception do
result := e.Message;
end;
end;
end.