项目作者: OpenPathInc

项目描述 :
Alternative Payment Methods (Apple Pay and Google Pay) for Heartland Payment Systems
高级语言: JavaScript
项目地址: git://github.com/OpenPathInc/OpHps.AltPay.git
创建时间: 2020-12-29T23:55:32Z
项目社区:https://github.com/OpenPathInc/OpHps.AltPay

开源协议:Other

下载


OpenPath Heartland Payment Systems Alternative Payment Methods

Alternative Payment Methods (Apple Pay and Google Pay) for Heartland Payment Systems

Sample Project

What you will need?

Already Included, But Available Separately

Useful Documentation

Getting Started

Setting up the project

Open the CSharpExample.sln solution found in the \ApplePayExample Folder in your code editor. Once your project is open, open the launchSettings.json located in the \ApplePayExample\CSharpExample\Properties and ensure the project is using iisExpress applicationUrl:http://localhost:44300. This is important if you are going to use one of our predefined and Apple Pay verified test domains through ngrok. If you want to use a different port, you can always adjust that in your ngrok settings to match your project.

Launch Settings
  1. "iisSettings": {
  2. "windowsAuthentication": false,
  3. "anonymousAuthentication": true,
  4. "iisExpress": {
  5. "applicationUrl": "http://localhost:44300",
  6. "sslPort": 0
  7. }
  8. }

Once the above configuration has been completed, you can now start the project, which will launch a web browser taking you to the Apple Pay Example home page. Most likely, either the device you are using or the browser will not be compatible with Apple Pay and you will not see the Apple Pay button, This is OK!

Setting up the proxy

In order to test Apple Pay, you will need a URL that have been validated by Apple Pay. In this example project, we have created 10 verified test domains you can setup using the ngrok proxy. We have already created the 10 batch files for each of these test domains; however, only 1 can be used at a time by any given tester; hence why we created 10 accounts.

In order to use the custom domains you will need a licensed copy of ngrok and add your ngrok key to the batch file. To fire up the proxy service, go to the /ngrok folder a select one of the 10 test accounts. Edit the selected batch file and add your ngrok key.

  1. ngrok http 44300 -host-header="localhost:44300" -subdomain=op-hps-apple-pay-0 -authtoken {YOUR-NGROK-API-KEY}
  2. pause

Save your changes and execute the batch file.

Once the proxy is running, you can now go to any Apple Pay compatible device and open up a Safari browser and browse to one domain you selected in your batch files.

https://op-hps-apple-pay-#.ngrok.io

If Apple Pay is supported by the browser and device an Apple Pay button will appear, which you can click and complete checkout.

Note that any transaction you do, does not actually charge the card you have associated with your Apple Pay account.

How it Works

Payment Method Update

Received Payload

  1. {
  2. "paymentMethod": {
  3. "displayName": null,
  4. "network": null,
  5. "type": "debit",
  6. "paymentPass": null
  7. },
  8. "update": {
  9. "newTotal": {
  10. "type": "final",
  11. "label": "Total",
  12. "amount": "12.62"
  13. },
  14. "newLineItems": [
  15. {
  16. "type": "final",
  17. "label": "Subtotal",
  18. "amount": "9.99"
  19. },
  20. {
  21. "type": "final",
  22. "label": "Shipping",
  23. "amount": "2"
  24. },
  25. {
  26. "type": "final",
  27. "label": "Taxes",
  28. "amount": "0.88"
  29. }
  30. ]
  31. }
  32. }

OpHps.AltPay.js

ApiLoginId

This is your unique key that associates your Apple Pay account with OpenPath and Heartland System, which can be found under sites in the OpenPath back office. https://client.openpath.io. For testing purposes, we have provided 10 varified ngrok URLs and matching API Login IDs, which can be found below.

OpHps.ApiLoginId(API Login ID)

  1. OpHps.ApiLoginId('XXXXXXXXXXXX');

PaymentCompleteReturnUrl

If the payment is successful this is the URL the server will redirect to with the details of the transaction in the query string.

OpHps.PaymentCompleteReturnUrl(Redirect URL)

  1. OpHps.PaymentCompleteReturnUrl('/payment-complete);ja

Returns the following paramaters

TransactionId
PacketId

  1. /payment-complete?TransactionId=4928399223&PacketId=4949223

EnableLogging

Enable logging turns on the debugging output to the browsers console and to an HTML element if assigned.

OpHps.EnableLogging(true|false)

  1. OpHps.EnableLogging(true);

Log

Will output messages to the logging service.

OpHps.Log(Message)

  1. OpHps.Log('Hey something happened here!');

AttachLog

If you want the browsers console output from the logger to also be updated on page, which can be useful when testing on mobile devices, you can attach the logger to an HTML element.

OpHps.AttachLog(Element Class or ID)

  1. OpHps.AttachLog('#log-output');

Example HTML Element

  1. <div id="log-output"></div>

ApplePay.AttachApplePayButton

In order to display the Apple Pay button your HTML must have a element that we can attach the button to, use this function to attach that elements Class or ID.

OpHps.ApplePay.AttachApplePayButton(Element Class or ID)

  1. OpHps.ApplePay.AttachApplePayButton('.apple-pay-button');

Example HTML Element

  1. <span class="apple-pay-button hidden"></span>

Attaching Endpoints

Once the Apple Pay button has been displayed and a user clicks on that button, the Apple Pay payment pane will be displayed to the user. In this pane, the user has the ability to change their shipping address, payment types and contact information, as well as choice a shipping method. When these items are changed, the corresponding endpoints will be called below. These endpoints will send the data that was changed and give you the ability to modify the pricing and shipping options available in the pane based on these changes. These endpoints must be available on your server and you must provide the updates.

ApplePay.AttachPaymentMethodSelectedEndpoint

When a user changes their payment type, such as Visa, Master Card, etc. this attached endpoint will be posted to.

OpHps.ApplePay.AttachPaymentMethodSelectedEndpoint(Endpoint)

  1. OpHps.ApplePay.AttachPaymentMethodSelectedEndpoint('/apple-pay/payment-method/' + cartId);

ApplePay.AttachShippingMethodSelectedEndpoint

When a user changes their shipping method this attached endpoint will be posted to.

OpHps.ApplePay.AttachShippingMethodSelectedEndpoint(Endpoint)

  1. OpHps.ApplePay.AttachShippingMethodSelectedEndpoint('/apple-pay/shipping-method/' + cartId);

ApplePay.AttachShippingContactSelectedEndpoint

When a user changes their shipping address this attached endpoint will be posted to.

OpHps.ApplePay.AttachShippingContactSelectedEndpoint(Endpoint)

  1. OpHps.ApplePay.AttachShippingContactSelectedEndpoint('/apple-pay/shipping-contact/' + cartId);

ApplePay.ShowApplePayButton

Once you’ve completed the initial configuration of Apple Pay, the final is to execute the Show Apple Pay Button function.

OpHps.ApplePay.ShowApplePayButton()

  1. OpHps.ApplePay.ShowApplePayButton();

ApplePay.SetCountryCode

To change the default currency of USD, you can set the country code, which in turn will change the currency.

OpHps.ApplePay.SetCountryCode(Two letter country code)

  1. OpHps.ApplePay.SetCountryCode('GB');

Examples

Country Country Code Currency Code
United States US USD
Great Britain GB GBP

ApplePay.Visa

Tells Apple Pay to accept or not accept Visa cards.

OpHps.ApplePay.Visa(true | false)

  1. OpHps.ApplePay.Visa(true);

ApplePay.MasterCard

Tells Apple Pay to accept or not accept Master Card cards.

OpHps.ApplePay.MasterCard(true | false)

  1. OpHps.ApplePay.MasterCard(true);

ApplePay.AmericanExpress

Tells Apple Pay to accept or not accept American Express cards.

OpHps.ApplePay.AmericanExpress(true | false)

  1. OpHps.ApplePay.AmericanExpress(true);

ApplePay.Discover

Tells Apple Pay to accept or not accept Discover cards.

OpHps.ApplePay.Discover(true | false)

  1. OpHps.ApplePay.Discover(true);

ApplePay.SupportNetwork

Beyond the above supported card networks, you can also add custom card networks as well.

OpHps.ApplePay.SupportNetwork(Card Network, Accept(true | false))

  1. OpHps.ApplePay.SupportNetwork('JCB', true)

ApplePay.SetTotal

The set total is the final amount that you want Apple Pay to charge.

OpHps.ApplePay.SetTotal(Total Amount)

  1. OpHps.ApplePay.SetTotal(19.99);

Line Items

The below option for line item applies NOT TO PRODUCT LINE ITEMS, but sub-total line items, for example if you wanted to display, tax, shipping and discounts, you would add each of these as a single line item with their amounts.

ApplePay.ClearLineItems

Clears all the current line items that are or would be displayed in the Apple Pay payment pane.

OpHps.ApplePay.ClearLineItems()

  1. OpHps.ApplePay.ClearLineItems();

ApplePay.AddLineItem

Adds a line item to the Apple Pay payment pane.

OpHps.ApplePay.AddLineItem(Label Descriptor, Amount)

  1. OpHps.ApplePay.AddLineItem('Sub-total', 19.99);
  2. OpHps.ApplePay.AddLineItem('Discount', -2.00);
  3. OpHps.ApplePay.AddLineItem('Tax', 1.43);

ShippingMethods

Since customer can select their shipping addresses from the Apple Pay payment pane, we need to also give them ability, if you are shipping a product, to select their desired shipping method and shipping prices, the following functions allow you to create available shipping methods and prices.

ApplePay.ClearShippingMethod

Clears the current shipping methods.

OpHps.ApplePay.ClearShippingMethod()

  1. OpHps.ApplePay.ClearShippingMethod();

ApplePay.AddShippingMethod

Adds a shipping options to the Apple Pay payment pane.

OpHps.ApplePay.AddShippingMethod(Name of Shipping Method, Total Shipping Amount, Unique Shipping Code, Additional Details (Shipping Date))

  1. OpHps.ApplePay.AddShippingMethod('3 Day Ground', 5.99, '3DG-UPS', 'Arives December 24th, 2021');

ApplePay.RequireShippingContactEmail

Forces the Apple Pay payment panel to require the customers emails address.

OpHps.ApplePay.RequireShippingContactEmail(true | false)

  1. OpHps.ApplePay.RequireShippingContactEmail(true);

ApplePay.RequireShippingContactName

Forces the Apple Pay payment panel to require the customers contact name.

OpHps.ApplePay.RequireShippingContactName(true | false)

  1. OpHps.ApplePay.RequireShippingContactName(true);

ApplePay.RequireShippingContactPhone

Forces the Apple Pay payment panel to require the customers phone number.

OpHps.ApplePay.RequireShippingContactPhone(true | false)

  1. OpHps.ApplePay.RequireShippingContactPhone(true);

ApplePay.RequireShippingContactAddress

Forces the Apple Pay payment panel to require the customers shipping address.

OpHps.ApplePay.RequireShippingContactAddress(true | false)

  1. OpHps.ApplePay.RequireShippingContactAddress(true);

ApplePay.RequiredShippingContactFields

Forces the Apple Pay payment panel to require the customers shipping contact fields.

OpHps.ApplePay.RequiredShippingContactFields(true | false)

  1. OpHps.ApplePay.RequiredShippingContactFields(true);

Testing

Test Accounts

ID API Login ID Verified Domain ngrok File Name
0 gptv7pAxQsyr9UQj https://op-hps-apple-pay-0.ngrok.io op-hps-apple-pay-0.ngrok.io.bat
1 pcjxXKJxZ4pdPASZ https://op-hps-apple-pay-1.ngrok.io op-hps-apple-pay-1.ngrok.io.bat
2 yhvyNkNKkcdWVd9q https://op-hps-apple-pay-2.ngrok.io op-hps-apple-pay-2.ngrok.io.bat
3 9WPdxye3NRU4zrCv https://op-hps-apple-pay-3.ngrok.io op-hps-apple-pay-3.ngrok.io.bat
4 47DxjThMjcxtWUsu https://op-hps-apple-pay-4.ngrok.io op-hps-apple-pay-4.ngrok.io.bat
5 pt5QEytmhd4A3aTm https://op-hps-apple-pay-5.ngrok.io op-hps-apple-pay-5.ngrok.io.bat
6 YfHn7S6CJ6tsv9aJ https://op-hps-apple-pay-6.ngrok.io op-hps-apple-pay-6.ngrok.io.bat
7 ncEaaKrmPeRzRTET https://op-hps-apple-pay-7.ngrok.io op-hps-apple-pay-7.ngrok.io.bat
8 wcGPXWkT5SzjM63M https://op-hps-apple-pay-8.ngrok.io op-hps-apple-pay-8.ngrok.io.bat
9 c2sTDMCYyQYrtq7q https://op-hps-apple-pay-9.ngrok.io op-hps-apple-pay-9.ngrok.io.bat