Advertisement
Guest User

Untitled

a guest
Apr 13th, 2011
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.87 KB | None | 0 0
  1. unit authorizenetsoapcall;
  2.  
  3. interface
  4.  
  5. uses Classes, SysUtils, AuthService, XSBuiltIns;
  6.  
  7. type
  8.  
  9.   TAuthorizeNetARB = class(TObject)
  10.   private
  11.     FMerc: MerchantAuthenticationType;
  12.     FArb: ARBSubscriptionType;
  13.     FRet: ARBCreateSubscriptionResponseType;
  14.     FAUTHORIZE_LOGIN: string;
  15.     FAUTHORIZE_KEY: string;
  16.     FMerchant_assigned_name: string;
  17.     FAmount: string;
  18.     FTrialamount: string;
  19.     FInterval_length: SmallInt;
  20.  
  21.     FStartdate_month: Word;
  22.     FStartdate_day: Word;
  23.     FStartdate_year: integer;
  24.  
  25.     FTotalOccurrences: SmallInt;
  26.     FTrialOccurrences: SmallInt;
  27.  
  28.     FCreditCard_cardNumber: string;
  29.     FCreditCard_expirationDate: string;
  30.     FCreditCard_cardCode: string;
  31.  
  32.     FCustomerID: string;
  33.     FCustomerEmail: string;
  34.     FCustomerPhone: string;
  35.     FCustomerFax: string;
  36.  
  37.     FBillTo_firstName: string;
  38.     FBillTo_lastName: string;
  39.     FBillTo_address: string;
  40.     FBillTo_city: string;
  41.     FBillTo_state: string;
  42.     FBillTo_zip: string;
  43.     FBillTo_country: string;
  44.  
  45.     // returns
  46.     FReturnCode: integer;
  47.     FReturnMessage: string;
  48.     FReturnSubscriptionID: string;
  49.     procedure InitSOAP;
  50.   public
  51.     constructor Create;
  52.     destructor Destroy; override;
  53.     function MakePayment: string;
  54.   published
  55.     property AUTHORIZE_LOGIN: string read FAUTHORIZE_LOGIN write FAUTHORIZE_LOGIN;
  56.     property AUTHORIZE_KEY: string read FAUTHORIZE_KEY write FAUTHORIZE_KEY;
  57.     property Merchant_assigned_name: string read FMerchant_assigned_name write FMerchant_assigned_name;
  58.     property Amount: string read FAmount write FAmount;
  59.     property Trialamount: string read FTrialamount write FTrialamount;
  60.     property Interval_length: SmallInt read FInterval_length write FInterval_length;
  61.     property Startdate_month: Word read FStartdate_month write FStartdate_month;
  62.     property Startdate_day: Word read FStartdate_day write FStartdate_day;
  63.     property Startdate_year: integer read FStartdate_year write FStartdate_year;
  64.     property TotalOccurrences: SmallInt read FTotalOccurrences write FTotalOccurrences;
  65.     property TrialOccurrences: SmallInt read FTrialOccurrences write FTrialOccurrences;
  66.     property CreditCard_cardNumber: string read FCreditCard_cardNumber write FCreditCard_cardNumber;
  67.     property CreditCard_expirationDate: string read FCreditCard_expirationDate write FCreditCard_expirationDate;
  68.     property CreditCard_cardCode: string read FCreditCard_cardCode write FCreditCard_cardCode;
  69.     property CustomerID: string read FCustomerID write FCustomerID;
  70.     property CustomerEmail: string read FCustomerEmail write FCustomerEmail;
  71.     property CustomerPhone: string read FCustomerPhone write FCustomerPhone;
  72.     property CustomerFax: string read FCustomerFax write FCustomerFax;
  73.     property BillTo_firstName: string read FBillTo_firstName write FBillTo_firstName;
  74.     property BillTo_lastName: string read FBillTo_lastName write FBillTo_lastName;
  75.     property BillTo_address: string read FBillTo_address write FBillTo_address;
  76.     property BillTo_city: string read FBillTo_city write FBillTo_city;
  77.     property BillTo_state: string read FBillTo_state write FBillTo_state;
  78.     property BillTo_zip: string read FBillTo_zip write FBillTo_zip;
  79.     property BillTo_country: string read FBillTo_country write FBillTo_country;
  80.     property ReturnCode: integer read FReturnCode;
  81.     property ReturnMessage: string read FReturnMessage;
  82.     property ReturnSubscriptionID: string read FReturnSubscriptionID;
  83.   end;
  84.  
  85. implementation
  86.  
  87. { TAuthorizeNetARB }
  88.  
  89. constructor TAuthorizeNetARB.Create;
  90. begin
  91.   FMerc := MerchantAuthenticationType.Create;
  92.   FArb := ARBSubscriptionType.Create;
  93. end;
  94.  
  95. destructor TAuthorizeNetARB.Destroy;
  96. begin
  97.   FMerc.Free;
  98.   FArb.Free;
  99.   FRet.Free;
  100.   inherited;
  101. end;
  102.  
  103. procedure TAuthorizeNetARB.InitSOAP;
  104. var
  105.   amount: TxsDecimal;
  106.   trialamount: TxsDecimal;
  107.   startdate: TXSDate;
  108. begin
  109.   amount := TxsDecimal.Create;
  110.   trialamount := TxsDecimal.Create;
  111.   startdate := TXSDate.Create;
  112.  
  113.   FMerc.name_ := AUTHORIZE_LOGIN;
  114.   FMerc.transactionKey := AUTHORIZE_KEY;
  115.   FArb.name_ := FMerchant_assigned_name;
  116.   amount.DecimalString := FAmount;
  117.   FArb.amount := amount;
  118.   trialamount.DecimalString := FTrialamount;
  119.   FArb.trialAmount := trialamount;
  120.   FArb.paymentSchedule := PaymentScheduleType.Create;
  121.   FArb.paymentSchedule.interval := PaymentScheduleTypeInterval.Create;
  122.   FArb.paymentSchedule.interval.length := Interval_length;
  123.   FArb.paymentSchedule.interval.unit_ := ARBSubscriptionUnitEnum.months;
  124.  
  125.   startdate.Month := Startdate_month;
  126.   startdate.Day := Startdate_day;
  127.   startdate.Year := Startdate_year;
  128.   FArb.paymentSchedule.startDate := startdate;
  129.   FArb.paymentSchedule.totalOccurrences := TotalOccurrences;
  130.   FArb.paymentSchedule.trialOccurrences := TrialOccurrences;
  131.  
  132.   FArb.payment := PaymentType.Create;
  133.   FArb.payment.creditCard := CreditCardType.Create;
  134.   FArb.payment.creditCard.cardNumber := CreditCard_cardNumber;
  135.   FArb.payment.creditCard.expirationDate := CreditCard_expirationDate;
  136.   FArb.payment.creditCard.cardCode := CreditCard_cardCode;
  137.  
  138.   FArb.customer := CustomerType.Create;
  139.   FArb.customer.id := FCustomerID;
  140.   FArb.customer.email := FCustomerEmail;
  141.   FArb.customer.phoneNumber := FCustomerPhone;
  142.   FArb.customer.faxNumber := FCustomerFax;
  143.  
  144.   FArb.billTo := NameAndAddressType.Create;
  145.   FArb.billTo.firstName := BillTo_firstName;
  146.   FArb.billTo.lastName := BillTo_lastName;
  147.   FArb.billTo.address := BillTo_address;
  148.   FArb.billTo.city := BillTo_city;
  149.   FArb.billTo.state := BillTo_state;
  150.   FArb.billTo.zip := BillTo_zip;
  151.   FArb.billTo.country := BillTo_country;
  152. end;
  153.  
  154. // make payment will return 0 as ReturnCode if the subscription is successfull
  155. function TAuthorizeNetARB.MakePayment: string;
  156. begin
  157.   result := '';
  158.   try
  159.     InitSOAP;
  160.     FRet := GetServiceSoap.ARBCreateSubscription(FMerc, FArb);
  161.     FReturnCode := integer(FRet.resultCode);
  162.     FReturnMessage := FRet.messages[0].text;
  163.     FReturnSubscriptionID := IntToStr(FRet.subscriptionId);
  164.   except
  165.     on e: Exception do
  166.       result := e.Message;
  167.   end;
  168. end;
  169.  
  170. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement