On this page, you can read how you can place a print order for a file which is not created yet and will be provided later. This applies for cases in which a file is created dynamically for custom-generated content (i.e. based on user input). This process works as a combination of the Print Button and the Print API.
1. Place Async Button
The first step is to place the ”asynchronous” button in your website. You can find a detailed description of this button in the button documentation in the section ”Hosting your own files without uploading”. Here is an example for that button. Note there’s no data-offering
nor data-publication
attribute.
<a title='Peecho' href='http://www.peecho.com/' data-width='216' data-height='279' data-pages='100' class='peecho-print-button' data-thumbnail='https://your/thumbnail/location' data-noprice='true' data-currency='EUR' data-reference='MERCHANTREFERENCE' data-locale='en_EN'> Test button </a>
2. Payment notification
When you or a customer clicks on the print button, they will be redirected to the Peecho checkout. In the checkout, they can specify the product details, shipping information and complete payment. When everything is done correctly, the customer will see a thank you page.
Meanwhile, the payment gateway will notify Peecho after payment confirmation, and Peecho will notify the merchant by issuing a GET request to the pingback URL you provide us, which should point to a location you have control over. The URL should have the following format:
https://website.com/peecho.php?peechoId=%PEECHOID%&merchantId=%MERCHANTID%&secret=%SECRET%
where:
%PEECHOID% – unique order reference defined by Peecho.
%MERCHANTID% – a reference defined at your end which you can use to identify your order. You can specify this merchant id in the button-script when placing the order, in a variable called ‘data-reference’.
%SECRET% – hash generated at our end. You can recreate the hash at your end to make sure nobody tampered with the data (optional).
At this stage, the order will be in the state “PENDING_COMPLETION” until you follow step 3.
3. Provide source file
In this last step you should provide a URL of the source file, so we can proceed with processing your order. This can be done at any time after your server receives our GET request (see above step). Take your time to prepare the file and then call this method:
POST /rest/order/set_source_url
Set the source URL of an order – only applicable for asynchronous source generation (if you generate a PDF after the order procedure has been completed).
Request
Parameter | Required | Explanation |
---|---|---|
orderId | Yes | The Peecho order reference. |
sourceURL | Yes | The full URL to the source document |
merchantApiKey | Yes | Unique string identifier of the merchant. |
secret | Yes | Base64 encoded HMAC SHA1 Hash of externalOrderId + merchantReference + sourceUrl using your merchantSecretKey as HMAC-key |
backgroundColor | No | Background color of spine. |
textColor | No | Color of text on spine. |
textSize | No | Size of text on spine. |
textCenter | No | Text in the center part spine. |
textTop | No | Text in the top part spine. |
textBottom | No | Text in the bottom part spine. |
textFamily | No | Font of spine text. (Arial, DarkCourier, Georgia, GochiHand, Helvetica, Tahoma, TimesNewRoman, Verdana) |
Curl
curl -v -d "orderId={yourExternalOrderId}&sourceUrl=https://dl.dropboxusercontent.com/u/5278037/mediamarkt.pdf&merchantApiKey={yourMerchantApiKey}&secret={generatedSecretHash}" "http://www.peecho.com/rest/order/set_source_url"
Java
String secretKey = "merchantSecretKey"; String externalOrderId = "1234"; String merchantReference = "merchantReference"; String sourceUrl = "http://somesourceurl.com/a.pdf"; String data = externalOrderId + merchantReference + sourceUrl; Mac m = Mac.getInstance("HmacSHA1"); m.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1")); byte[] hash = m.doFinal(data.getBytes("UTF-8")); String secret = new String(Base64.encodeBase64(hash)); /* You get as result: MjavkJnEj5SrkHYWtO65KDWEw3M= (using org.apache.commons.codec.binary for base64 and javax.crypto for Mac). */
Response
This service either returns 'OK' or an error status.
Simple as that!
After completing these simple steps, your order will be processed, printed and shipped.
Comments
0 comments
Article is closed for comments.