dokuz-beyaz-logo

WordPress WooCommerce veri çekme dokümantasyonu

WordPress WooCommerce yapan e-ticaret sahipleri oluşturduğu rest api ile verilerini nasıl çeker size onu anlatacağım.

Öncelikle Postman ile veri çekebiliyormuyuz onu ayarlamamız gerekiyor.

Yukarıdaki resimde görüldüğü üzere bir rest api key ayrıca secret key oluşturmak gerekiyor.

Önemli Not: burada mutlaka web sitenizi yapan wordpress uzmanına başvurmalısınız. Veriyi sadece okuma yetkisi bile verseniz mutlaka güvenlik açıklarını engelleyen yöntemlerin sisteme uygulanması gerekmektedir. Sonradan sizin dediklerinizi yaptım ve  hacklendim demeyin, Biz de bu konuda bir uzmandan destek aldık, ayrıca bu dokümanın amacı veri entegrasyonu kısmı ile ilgili sizlere aydınlatıcı bilgiler vermektir.

Verinin postman den geldiğini gördükten sonra yapılması gereken kodlama kısmı da c# da örnek olarak kodlanmıştır.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            GetWP();
        }
        async void GetWP()
        {
            OperationWP owp= new OperationWP();
            List<Order> response = await owp.GetOrders("https://falanca.com.tr/wp-json/wc/v3/orders?consumer_key=**************************&consumer_secret=****************");
            
        }
    }

Entegrasyon kapsamında veri çekme süreçlerinin tamamını operasyon diye nitelendiririz, bu sürecin adına operasyon dememizin bir nedeni de tüm bu methodların içindeki süreçleri diğer süreçlerden soyutlamak içindir. Çünkü bir entegrasyon bir projedir ve mikro servis yapıda bir çok entegrasyon geliştirip tüm bu süreçlerin birbirini etkilememesi sağlanmalıdır.

public class OperationWP
   {
       public static JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
       {
           PropertyNameCaseInsensitive = true,
           AllowTrailingCommas = true,
           ReadCommentHandling = JsonCommentHandling.Skip,
           Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
           IncludeFields = true,
       };
 
       public async Task<List<Order>> GetOrders(string serviceurl)
       {
           bool disableGoto = false;
 
 
           HttpClient httpClient = new HttpClient();
 
           var ApiResult = await httpClient.GetAsync(serviceurl);
 
           if (ApiResult.StatusCode != System.Net.HttpStatusCode.OK && !disableGoto)
           {
               //Hata oldu
           }
 
           var responseJson = await ApiResult.Content.ReadAsStringAsync();
           var OrderRes= JsonSerializer.Deserialize<List<Order>>(responseJson, jsonSerializerOptions);
 
 
           return InvoiceRes;
       }
   }

Tabi bu veriyi bir class’a atmak için önceden bu veri setine ait class’ın da oluşturulması gerekmektedir.

public class Billing
    {
        public string first_name { getset; }
        public string last_name { getset; }
        public string company { getset; }
        public string address_1 { getset; }
        public string address_2 { getset; }
        public string city { getset; }
        public string state { getset; }
        public string postcode { getset; }
        public string country { getset; }
        public string email { getset; }
        public string phone { getset; }
    }
 
    public class Collection
    {
        public string href { getset; }
    }
 
    public class Customer
    {
        public string href { getset; }
    }
 
    public class FeeLine
    {
        public int id { getset; }
        public string name { getset; }
        public string tax_class { getset; }
        public string tax_status { getset; }
        public string amount { getset; }
        public string total { getset; }
        public string total_tax { getset; }
        public List<object> taxes { getset; }
        public List<object> meta_data { getset; }
    }
 
    public class Image
    {
        public object id { getset; }
        public string src { getset; }
    }
 
    public class LineItem
    {
        public int id { getset; }
        public string name { getset; }
        public int product_id { getset; }
        public int variation_id { getset; }
        public int quantity { getset; }
        public string tax_class { getset; }
        public string subtotal { getset; }
        public string subtotal_tax { getset; }
        public string total { getset; }
        public string total_tax { getset; }
        public List<object> taxes { getset; }
        public List<MetaData> meta_data { getset; }
        public string sku { getset; }
        public int price { getset; }
        public Image image { getset; }
        public object parent_name { getset; }
    }
 
    public class Links
    {
        public List<Self> self { getset; }
        public List<Collection> collection { getset; }
        public List<Customer> customer { getset; }
    }
 
    public class MetaData
    {
        public int id { getset; }
        public string key { getset; }
        public string value { getset; }
        public string display_key { getset; }
        public string display_value { getset; }
    }
 
    public class Order
    {
        public int id { getset; }
        public int parent_id { getset; }
        public string status { getset; }
        public string currency { getset; }
        public string version { getset; }
        public bool prices_include_tax { getset; }
        public DateTime date_created { getset; }
        public DateTime date_modified { getset; }
        public string discount_total { getset; }
        public string discount_tax { getset; }
        public string shipping_total { getset; }
        public string shipping_tax { getset; }
        public string cart_tax { getset; }
        public string total { getset; }
        public string total_tax { getset; }
        public int customer_id { getset; }
        public string order_key { getset; }
        public Billing billing { getset; }
        public Shipping shipping { getset; }
        public string payment_method { getset; }
        public string payment_method_title { getset; }
        public string transaction_id { getset; }
        public string customer_ip_address { getset; }
        public string customer_user_agent { getset; }
        public string created_via { getset; }
        public string customer_note { getset; }
        public DateTime? date_completed { getset; }
        public DateTime? date_paid { getset; }
        public string cart_hash { getset; }
        public string number { getset; }
        public List<MetaData> meta_data { getset; }
        public List<LineItem> line_items { getset; }
        public List<object> tax_lines { getset; }
        public List<object> shipping_lines { getset; }
        public List<FeeLine> fee_lines { getset; }
        public List<object> coupon_lines { getset; }
        public List<object> refunds { getset; }
        public string payment_url { getset; }
        public bool is_editable { getset; }
        public bool needs_payment { getset; }
        public bool needs_processing { getset; }
        public DateTime date_created_gmt { getset; }
        public DateTime date_modified_gmt { getset; }
        public DateTime? date_completed_gmt { getset; }
        public DateTime? date_paid_gmt { getset; }
        public string currency_symbol { getset; }
        public Links _links { getset; }
    }
 
    public class Self
    {
        public string href { getset; }
        public TargetHints targetHints { getset; }
    }
 
    public class Shipping
    {
        public string first_name { getset; }
        public string last_name { getset; }
        public string company { getset; }
        public string address_1 { getset; }
        public string address_2 { getset; }
        public string city { getset; }
        public string state { getset; }
        public string postcode { getset; }
        public string country { getset; }
        public string phone { getset; }
    }
 
    public class TargetHints
    {
        public List<string> allow { getset; }
    }

Çekilen verinin veri setini de aşağıdaki gibi görebilirsiniz. Veriyi çektikten sonra dilediğiniz gibi veri tabanına yazabilir yada istediğiniz ticari sisteme sipariş olarak aktarabilirsiniz. Bu veri çekme işlemini yaptıktan sonra biz Logo, Mikro, DİA, Netsis gibi muhasebe programlarına aktarıyoruz. Talep olursa örnek olarak Netsis e sipariş olarak aktardığımız kısmın kodlama sürecini de ayrıca paylaşabiliriz. Fakat unutulmamalıdır ki, entegrasyon süreçleri hep 2 bacaklıdır hatta bazen daha fazla yönlü olabilir. Verinin çekilmesi bir operasyon, verinin yazılması başka bir operasyon olabilir.

Facebook
Pinterest
Twitter
LinkedIn

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir