pay.secupay

datenbanken programmierung asp.net

pay.secupay Beispiele

Logo pay.secupay
pay.secupay

Anbei fünf Code Beispiele für die Nutzung.


Config File

<?xml version="1.0" encoding="utf-8"?>
<TPaySecupayConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Username>pay.secupay</Username>
  <ConnectionString>data source=localhost;initial catalog=Secupay;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework</ConnectionString>
  <ApiKey>133cb4492ced4f3f95a0b8e2823e301d</ApiKey>
  <Demo>1</Demo>
  <SecupayUrl>https://api-dist.secupay-ag.de</SecupayUrl>
  <UrlSuccess>http://www.ihre-shop-domain.de/pay.secupay.web/success.aspx</UrlSuccess>
  <UrlFailure>http://www.ihre-shop-domain.de/pay.secupay.web/failure.aspx</UrlFailure>
  <UrlPush>http://www.ihre-shop-domain.de/pay.secupay.web/push.ashx</UrlPush>
</TPaySecupayConfig>

Read Write Config File

Im Betriebe wird hauptsächlich nur noch die Load Methode benötigt, um die Standardkonfiguration einzulesen.
Auf den Gebrauch der web.config (app.config) wurde bewusst verzichtet, um Neustarts der Applikation im Betrieb zu verhindern.

Der ConnectionString muss für den Betrieb im Webserver angepasst werden. Der Zugriff auf die DB über integrated security=True ist vom Webserver aus in der Regel nicht erfolgreich.

// neue Config Datei erzeugen
TPaySecupayConfig config = new TPaySecupayConfig
{
    ApiKey = "133cb4492ced4f3f95a0b8e2823e301d", 
    ConnectionString = "data source=localhost;initial catalog=Secupay;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework",
    UrlSuccess = "http://www.ihre-shop-domain.de/success.aspx",
    UrlFailure = "http://www.ihre-shop-domain.de/failure.aspx",
    UrlPush = "http://www.ihre-shop-domain.de/push.aspx",
    Demo = 1,
    SendDeliveryAddress = true,
    Username = "pay.secupay"
};
 
// Datei speichern 
config.WriteToFile("secupay.xml");
 
// Config Datei mit Dateinamen einlesen
TPaySecupayConfig config2 = TPaySecupayConfig.LoadFromFile("secupay.xml");
Assert.IsNotNull(config2);
 
// Config Datei mit Default Dateinamen einlesen
TPaySecupayConfig config3 = TPaySecupayConfig.LoadFromFile();
Assert.IsNotNull(config3);

Initiate Payment

// config einladen
TPaySecupayConfig config = TPaySecupayConfig.LoadFromFile(ConfigFileName);
 
// Über Factory paySecupayInit Objekt erzeugen
PaySecupayInit secupayInit = new TPayFactory(config).CreateSecupayInit(1.23m);
 
// Daten aus Verkauf übertragen
secupayInit.Firstname = "Karl";
secupayInit.Lastname = "Mustermann";
secupayInit.Langauge = "DE";
secupayInit.Street = "Hauptstrasse";
secupayInit.Housenumber = "12";
secupayInit.Zip = "50000";
secupayInit.City = "Köln";
secupayInit.Telephone = "000-111222555";
secupayInit.Email = "";
secupayInit.PaymentAction = EnumPaymentAction.sale.ToString();
secupayInit.PaymentType = EnumPaymentType.creditcard.ToString();
 
 
// Inhalt des Warenkorbs anfügen
secupayInit.Basket.Add(new PaySecupayBasket
{
    Name = "Item1",
    ArticleNumber = "01-1111",
    Ean = "11111111111111111",
    Model = "Model",
    Price = "100",
    Quantity = "1",
    Tax = "19",
    Total = "100",
}.SetNew(config.Username));
 
// Lieferadresse übergeben
secupayInit.DeliveryAddress = new PaySecupayDeliveryAddress
{
    Firstname = secupayInit.Firstname,
    Lastname = secupayInit.Lastname,
    Company = secupayInit.Company,
    Street = secupayInit.Street,
    Housenumber = secupayInit.Housenumber,
    Zip = secupayInit.Zip,
    City = secupayInit.City,
    Country = secupayInit.Country
}.SetNew(config.Username);
 
// Payment beim Gateway anfordern --> Hash und IFrame Url werden geliefert
var man = new TPaySecupayManager(config);
man.InitPayment(secupayInit);
 
Process.Start(secupayInit.ResponseIFrameUrl);

Process Push

Nach erfolgreicher oder fehlerhafter Transaktion meldet das Gateway von Secupay eine Statusänderung an an eine der konfigurierten urls zurück.
In diesem Beispiel wird der Antwort von einem Generig Handler (ASHX Page) in ASP.NET aufgefangen.

Die Komponente pay.secupy wird die Push Nachricht im SQL Server speichern und das Objekt für die weitere Verarbeitung zur Verfügung stellen.

Die Verarbeitung der Daten im Webshop erfolgt dann im Anschluss an der mit dem Kommentar markierten Stelle.
//TODO: Hier weitere Logik ziehen

// Config einladen
string configfileName = context.Server.MapPath("~/APP_DATA/secupay.xml");
TPaySecupayConfig config = TPaySecupayConfig.LoadFromFile(configfileName);
 
if (context.Request.UrlReferrer == nullreturn;
 
// Manager starten
TPaySecupayManager man = new TPaySecupayManager(config);
        
// Verarbeitung Push
PaySecupayPush puschOut = man.ProcessPush(context.Request.Form, context.Request.RawUrl, context.Request.UrlReferrer.ToString());
 
// Antwort von Push senden
context.Response.Write(puschOut.PostOut);
        
//TODO: Hier weitere Logik ziehen

Process Status Request

Nach der Weiterleitung auf die Success oder Failure Seite durch das Gateway, muss der Status der Transaktion mit Hilfe des Hashwertes abgefragt werden. Die Kommunikation erfolgt synchron und das Ergebnis steht im Anschluss im Objekt PaySecupayStatus zur Verfügung.

TPaySecupayConfig config = TPaySecupayConfig.LoadFromFile(ConfigFileName);
 
// TODO: insert hashcode here
PaySecupayStatus secupayStatus = new TPayFactory(config).CreateSecupayStatus("---hashcode----"); 
var man = new TPaySecupayManager(config);
man.StatusPayment(secupayStatus);