Giter Site home page Giter Site logo

baltpeter / internetmarke-php Goto Github PK

View Code? Open in Web Editor NEW
36.0 12.0 9.0 36 KB

A PHP wrapper for the Deutsche Post Internetmarke web service 1C4A ("OneClickForApplikation")

License: MIT License

PHP 100.00%
stamp deutsche-post internetmarke 1c4a php hacktoberfest

internetmarke-php's Introduction

internetmarke-php – Simple PHP wrapper for the Internetmarke API

Simple PHP wrapper for the 1C4A (“OneClickForApplikation”) web service for the Internetmarke provided by Deutsche Post (DPAG).

Ordering a stamp using internetmarke-php

This project’s main purpose is to be able to order Deutsche Post stamps directly from your own applications. The payment is handled via the Portokasse, a prepaid wallet service also by Deutsche Post.

The web service by Deutsche Post is a custom SOAP API (see the WSDL here: https://internetmarke.deutschepost.de/OneClickForAppV3?wsdl). This project aims to abstract the SOAP nature away and provide a PHP API, while still adhering to the structure defined by DPAG. Do note that this is only a very thin wrapper around the SOAP API and the user still has to follow DPAG’s specification.

Requirements

To access the web service, you will need to register as a partner with DPAG. This can either be done via their website (German only) or by contacting [email protected]. They ask you to fill out following form. So keep in mind to fill it out first. (German only).
They will send you the documentation for the web service and create your personal credentials (consisting of: your partner ID, a secret key called SCHLUESSEL_DPWN_MARKTPLATZ, and a key phase which is usually 1).

In addition, you will need to have an account for the Portokasse service. This is a prepaid wallet from which your purchase totals will be deducted.
After registering, you can access the service with your username (email address) and password.

Installation

The package is available via Composer. To install the latest version from Packagist, run:

composer require baltpeter/internetmarke-php

Basic Usage

All actions provided by the web service are implemented in the baltpeter\Internetmarke\Service class.

This example shows you how to order a single stamp for a domestic letter. Other actions and parameters are documented with phpDoc. For more examples, please refer to the wiki.

// The `PartnerInformation` object is used to authenticate you as a partner with DPAG.
$partner_info = new \baltpeter\Internetmarke\PartnerInformation('ABCDE', 1, 'yoursecretkey');
// The `Service` object provides an interface for all actions in the web service.
$service = new \baltpeter\Internetmarke\Service($partner_info);

// First, we need to get a token for our Portokasse user.
$user_token = $service->authenticateUser('[email protected]', 'yourpassword')->getUserToken();

// Next, we create an `OrderItem` which holds the details of the stamp we want to purchase.
$order_item = new \baltpeter\Internetmarke\OrderItem(1, null, null,
    new \baltpeter\Internetmarke\Position(1, 1, 1), 'FrankingZone');

// Finally, we call `checkoutShoppingCartPdf()` which creates the order and actually
// deducts the money from your Portokasse.
// The last parameter in this example is the total cost in eurocents, which you have to calculate
// manually. This value *has* to be correct, it is checked on the server side.
var_dump($service->checkoutShoppingCartPdf($user_token, 1, array($order_item), 80));

Running this code will print a result similar to this:

object(stdClass)#10 (3) {
  ["link"]=>
  string(111) "https://internetmarke.deutschepost.de/PcfExtensionWeb/document?keyphase=0&data=abcdefghijklmopqrstuvwxyz"
  ["walletBallance"]=>
  int(236725)
  ["shoppingCart"]=>
  object(stdClass)#11 (2) {
    ["shopOrderId"]=>
    string(9) "12345678"
    ["voucherList"]=>
    object(stdClass)#12 (1) {
      ["voucher"]=>
      array(1) {
        [0]=>
        object(stdClass)#13 (1) {
          ["voucherId"]=>
          string(20) "A0011E78E1000001234A"
        }
      }
    }
  }
}

Note how we wrapped the $order_item in an array. If you want to order multiple stamps, just include more OrderItems in that array.

The stamp in the linked PDF will look something like this:

The generated stamp

Again, please refer to the wiki for more examples.

License

internetmarke-php is licensed under the MIT license, see the LICENSE file for details. Pull requests are welcome!

internetmarke-php's People

Contributors

baltpeter avatar deltachaos avatar iwasherefirst2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

internetmarke-php's Issues

Multible OrderItem with same NamedAddress

org.xml.sax.SAXParseException; cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'ns1:address'

  $this->service->checkoutShoppingCartPdf
  (
    $this->token,
    108,// Zweckform 3659 Etiketten 97 x 42.3
    [
      new \baltpeter\Internetmarke\OrderItem
      (
        21,
        null,
        $address_binding,
        new \baltpeter\Internetmarke\Position(1, 1, 1),
        'AddressZone'
      ),
      new \baltpeter\Internetmarke\OrderItem
      (
        21,
        null,
        $address_binding,
        new \baltpeter\Internetmarke\Position(2, 1, 1),
        'AddressZone'
      )
    ],
    (145 * 2)
  );

Portokasse Login

Hey,

thank you for this awesome package, it was helping me a lot.

I noticed that there is no class for "Portokasse laden" (see Technische Beschreibung page 15).
I think its useful to have such a class with all properties that are relevant for the form and a method to compute the special signature. Shall I add this as a PR or do you not want this is in your project?

Custom Pageformat 24 labels per A4 Page generation

Hello,

I would like 24 labels with sender and receiver adress included on the label per page, but i not found pre defined label format that i get with retrievePageformats method where this is possible with adress, the documentation of the Internetmarke api says that custom pageformats mot possible, so i think i have to produce 24 labels for e.g. Brother defined label and merge it by me to a A4 Pdf Page, knows somebody a better smarter solution, pls help.

how i can add more than 1 order items

it works perfekt with one order item, but if i try to add more in the array i get an error message!
Fatal error: Uncaught SoapFault exception: [soap:Server] Checkout shopping cart failed

How i can fix this problem?

thanks a lot!

How I can get availible Products from Prodws

Hello,

can somebody help me, how can i get availible products from ProdWs, which header paramaeters i have to send is the mandant id same like the Partner ID, example request with headers an endpoint pls.

BR

Where to find ProductCode ?

I'm unable to find the definition for the Product_Code List.
So in OrderItem, ProductCode 1 is a 0,80€ Letter?
What ProductCode would a 1,45€ Letter be?

Zusatzleistungen / Trackingcode

Hallo,

ist es möglich auch Zusatzleistungen wie Einschreiben zu buchen?
Ich denke man müsste dann eine andere ProductId übergeben.
Gibt es einen Weg die Ids auszulesen?

Question: Charging Portkasse

Hi,

why would you use a form to then redirect users to the payment page? Why not just directly redirect to the payment page?

[soap:Client] Unmarshalling Error: cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'ns1:positions'

Besides the fix in #3, the following example still leads to a crash [soap:Client] Unmarshalling Error: cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'ns1:positions'

$order_item = new \baltpeter\Internetmarke\OrderItem(1, null, null,
    new \baltpeter\Internetmarke\Position(1, 1, 1), 'FrankingZone');

$x = $service->checkoutShoppingCartPNG($user_token, [$order_item,$order_item], 160);

I also don't know how to fix it, besides just making a deep copy like this:

  public function checkoutShoppingCartPng($user_token, $positions, $total, $shop_order_id = null,
                                            $ppl_id = null, $create_manifest = null, $create_shipping_list = null) {

        $distinct_positions = [];
        foreach ($positions as $position) {
          $distinct_positions[] = deep_copy($position);
        }

        $result = $this->__soapCall('checkoutShoppingCartPNG', array('CheckoutShoppingCartPNGRequest' => array(
            'userToken' => $user_token, 'shopOrderId' => $shop_order_id, 'ppl' => $ppl_id, 'positions' => $distinct_positions,
            'total' => $total, 'createManifest' => $create_manifest, 'createShippingList' => $create_shipping_list
        )));

Maybe I overlook something, but isn't the error only appearing in
checkoutShoppingCartPdf and checkoutShoppingCartPng? If thats the case, we could get rid of all deep copy calls that where introduced in #3.

If thats correct, then I could make a PR to fix it.

unzipPNG function

Hello,

is there an example how to use the unzipPNG function?

Thank you.
Best Regards,
Dieter

Error 503 if portokasse-mode not prepaid

hiho, we got a 503 error, after our portokasse was switchet to "Postpaid" (from '"prepaid" i think). with prepaid your class worked well. is there a context?

regards and many thanks
joey

Bug: Country does not show up

Hey,

I tested the example and want to use this service to order some stamps. But I experienced that countries do not show up in the final stamp. My code looks like this Example in the Wiki.

How to fix this issue?

Best regards
Niels

Create improved return object for checkoutShoppingCartPng?

Hi,

I noticed that checkoutShoppingCartPng returns a stdClass. When one wants to access the png or png's, then this is a difficult task, because the stdClass only points to a zip file.

I thought maybe we could replace the stdClass with a proper class that contains a method to unzip it and returns an array of the url's to the pictures. As a parameter one would have to give a path to the directory where the images and the zip file should be unzipped. And the new class should be so, that it does not break old code.

Shall I create a PR for this or do you not like it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.