1.1.42 • Published 3 years ago

payper-widget v1.1.42

Weekly downloads
24
License
ISC
Repository
-
Last release
3 years ago

 

alt text

   

One-click payment.

Getting Started


Create a folder for the Payper source code.

Download the project using npm install or from the git repository

npm install payper-widget

The project has been designed so that you don't have to make any modifications to the source code or recompile. Out of the box, it is ready to be installed into your payment page.

Compiling

If you haven't already, install yarn.

npm install --global yarn

Install Webpack

npm install --save-dev webpack

To compile, use the command yarn wp to call Webpack to do the compiling.

When you're ready, copy the following to your project root:

  • build folder
  • payper-logo folder
  • index.html
  • payper.css

Adding your Company Logo

Your company logo must be symmetrical and be no larger than 100x100 pixels.

Within the root directory of the Payper Widget, create a folder called payper_logo.

Adding Logo Without Recompiling the project

Add your company logo in the payper-logo folder with the name logo.png.

If you prefer to use another file type or a different file name, you will have to recompile the project

Adding Logo with Intent to Recompile

  1. Within the src\components\CompanyLogo\CompanyLogo file, update the line 9:
  • <img className="logo-image" src={window.location.href + '/payper_logo/logo.png'} />
  • Note - the image source path starts within the current folder
  1. Replace logo.png with the file and path of your choice.
  2. Recompile yarn wp

Adding the Widget to your Checkout Page

Your checkout page will need a dedicated <div> to be the Payper Widget's home. Call this <div id="payper-widget"> .

Calling the Payper Widget

Insert this script into your payment page;

<script src="./build/index.js" id="Payper-Script" data-config="{'values': 'sendValues','config': {'targetElementId': 'payper-widget'}}" >
  (function (w, d, s, o, f, js, fjs) {
    w['Payper-Widget'] = o; w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
    js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
    js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
  }(window, document, 'script', 'sendValues', './build/index.js'));
  w1('init', { targetElementId: 'payper-widget' });
</script>

Make sure the scr attribute accurately points to the folder.

The script will consume the JSON when the button is clicked.

Adding the Payment Button

The Pay with Payper button will call the function to deliver the JSON payload to the Payper Widget:

<button onclick="sendValues('apidata', JSONData);">Pay with Payper</button>

The JSON Object

Your payment information will be sent to the Payper Widget via JSON payload.

{
    "sid_info": [{
       "sid":"",
       "type":"",
    }],
    "rcode":"",
    "company_name":"",
    "return_url":"",
    "notification_url":"",
    "udf1":"",  
    "udf2":"",  
    "udf3":"",  
    "udf4":"",  
    "udf5":"",  
    "udf6":"",
    "first_name":"",
    "last_name":"",
    "email":"",
    "address":"",
    "city":"",
    "state":"",
    "zip_code":"",
    "items": [{
        "name":"",
        "unit_price":"",
        "quantity":""
    }],
    "amount_shipping":"",
}

JSON Parameters

ParamaterDescriptionTypeRequirement
Account Information
sid_infoArray of SID informationarrayrequired
sidsid number provided by Payper. e.g. 123integerrequired
typedescription of sid level standard or enhancedstringrequired
Customer Information
first_nameCustomer's first namestringrequired
last_nameCustomer's last namestringrequired
emailCustomer's email addressstringrequired
phoneCustomer's phone numberstringrequired
addressCustomer's street addressstringrequired
cityCustomer's citystringrequired
stateCustomer's statestringrequired
ISO format - 2/3 characters
countryCustomer's countrystringrequired
ISO format - 2 characters
zip_codeCustomer's Zip/Postal Codestringrequired
USA customers: 5-digit ZIP code (eg. "12345")
Canadian customers: 6-character alphanumeric postal code (eg. "A1A 1A1")
Merchant URLs
return_urlThe URL to return the customer to after processingstringrequired
notification_urlThe URL to receive asynchronous status notificationsstringoptional
Cart Information
itemsarray of unit_price, quantity, namearrayrequired
unit_priceThe amount that you want to charge per unit, e.g. 10.00 if you would want to charge $10.00 per unitdecimalrequired
quantityThe number of units purchasedintegerrequired
nameThe name of the item being purchased - for display to customerstringrequired
amount_shippingSpecify the shipping cost. This value is added to the total of the cart before chargingdecimalrequired
udf1 - udf6User defined fields 1 through 6. These can be used to reference your internal transaction number, etc. These fields are returned unmodified in the responsestringAt least one UDF is required
Note: at least one of the UDF fields must be unique to each transaction.
e.g. UDF1 = transactionNumber, UDF2 = Date, etc...

Notification URL


This is the URL which you may receive asynchronous payment notifications and updates.

URLYour Notification URL
MethodPOST
Content-Typeapplication/x-www-form-urlencoded

Notification Request Parameters

ParameterTypeDescription
parent_txidstringThe transaction id of the initial transaction of the initial transaction request
txidstringThe transaction id of the current request
amountstringThe transaction amount, formatted with currency, ready for display
amount_rawdecimalThe transaction amount, as an unformatted, raw, decimal number
commentstringNotes assigned to the current transaction
tx_actionstringThe type of action performed (eg. PAYMENT, REFUND, PAYOUT, etc)
parent_txactionstringThe type of action that was initially processed (eg. PAYMENT, PAYOUT, etc)
statusstringThe status of the processed action (eg. APPROVED, DECLINED, ERROR, REFUNDED, etc)
descriptorstringWhat should show on the customer's bank statement
udf1 - udf6stringUser defined fields 1 through 6, returned as recorded in the initial transaction
signature_v2stringThe signature is a SHA256 HMAC hash used to verify the authenticity of the submitted data. See Signature generation for details on generating the signature

Signature generation

To generate a valid hash, generate the following string (be sure to include the pipes):

"sid|txid|status|amount_raw|descriptor"

example: "1|1234567890123456|APPROVED|10.00|Test descriptor +1234567890"

Then produce a SHA256 HMAC of this string, using your R-Code as the HMAC key.

With an R-Code of a52F84f9590218BfC499dab4cd751EEe

the above example would become: 0d8ded7cc4716c6ee2fb2cd35d6a0181085e01b6bc4d5344ba9219c40070f026