0.2.3 • Published 11 months ago

rn-amazon-payment-services v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

rn-amazon-payment-services

Amazon Payment Service Sdk react native package

Installation

npm install rn-amazon-payment-services

Android

You need to add the repository to your build file. Add it in your root build.gradle (/android/build.gradle) at the end of repositories

allprojects {
  repositories {
    ...
      maven { url "https://android-sdk.payfort.com" }
  }
}

You need to also make sure that following two permission are set in the AndroidManifest.xml (android/app/src/main/AndroidManifest.xml):

    < uses-permission android:name="android.permission.INTERNET" />
    < uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

iOS

1- Add the following code to your Podfile (inside the target section):

pod 'PayFortSDK'

2- Add the following to the bottom of your Podfile:

   post_install do |installer|
        installer.pods_project.targets.each do |target|
          if ['PayFortSDK'].include? target.name
            target.build_configurations.each do |config|
                config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
            end
          end
        end
      end

Usage

import {
  getDeviceId,
  FortRequestObject,
  StandardCheckout,
} from 'rn-amazon-payment-services';

// ...

export default function App() {

  const [deviceId, setDeviceId] = useState<string>('');
  const [showStandardCheckout, setShowStandardCheckout] = useState<boolean>(false);

  const setupDeviceId = async () => {
    const id: string = await getDeviceId();
    setDeviceId(id);
  };

  const onSuccess = (response: any) => {
    console.log('success', response);
    setShowCustomScreen(false);
  };

  const onFailure = (response: any) => {
    console.log('failure', response);
    setShowCustomScreen(false);
  };

  const onCancel = (response: any) => {
    console.log('cancel', response);
    setShowStandardCheckout(false);
  };

  // request object example for standard and custom ui checkout
  const requestObject: FortRequestObject = {
    command: 'PURCHASE',
    merchant_reference: 'ORD-0000007682',
    amount: '100',
    currency: 'AED',
    language: 'en',
    customer_email: 'sam@gmail.com',
    sdk_token: sdkToken,
    payment_option: 'VISA',
  };

  //...

  // Standard Checkout component
  return(
      <StandardCheckout
        showStandardCheckoutPage={showStandardCheckout}
        environment={'TEST'}
        requestCode={123455}
        showLoading={true}
        showResponsePage={true}
        requestObject={requestObject}
        onSuccess={onSuccess}
        onFailure={onFailure}
        onCancel={onCancel}
      />
  )
}

// ...

Standard Checkout Props

NameValueDescriptionMandatory
showStandardCheckoutPagebooleanNavigates to Amazon Payment Service Standard Checkout screenYes
environment'TEST', 'PRODUCTION'Parameter used to determine whether the request is going to be submitted to the test or production environment.Yes
requestCodenumberUnique ID for this request.Yes
showLoadingbooleanFlag to show or hide the loading dialog.Yes
showResponsePagebooleanFlag to show or hide response page after payment is done.Yes
requestObjectobjectParameters you need to send when you send a request (the full list of parameters is in the last section of the document)Yes
onSuccessfunctionCallback to handle when the transaction is processed successfully.Yes
onFailurefunctionCallback to handle when the transaction is failed.Yes
onCancelfunctionCallback to handle when the user cancels the payment by clicking the back button.No

Custom UI Checkout

import {
  CustomCheckoutView,
} from 'rn-amazon-payment-services';


// ...


// Custom Checkout UI component
  return(
    <CustomCheckoutView
      requestObject={requestObject}
      environment={'TEST'}
      style={{ width: 300, height: 400 }}
      payButtonProps={{
        marginLeft: 20,
        marginTop: 20,
        backgroundColor: '#026cff',
        text: 'Pay',
        textSize: 20,
        textColor: '#ffffff',
        buttonWidth: 40,
        buttonHeight: 40,
        borderRadius: 20,
        borderWidth: 1,
        borderColor: '#383333',
      }}
      onFailure={onFailure}
      onSuccess={onSuccess}
    />
  )

Direct Pay Checkout

import {
  DirectPayButton,
  FortRequestObjectDirectPay,
} from 'rn-amazon-payment-services';

//...

  const requestObjectDirectPay: FortRequestObjectDirectPay = {
    command: 'AUTHORIZATION',
    merchant_reference: 'ORD-0000007682',
    amount: '100',
    currency: 'AED',
    language: 'en',
    customer_email: 'sam@gmail.com',
    sdk_token: sdkToken,
    payment_option: 'VISA',
    token_name: tokenName,
    card_security_code: '123',
  };


  return(
      <DirectPayButton
        requestObject={requestObjectDirectPay}
        environment={'TEST'}
        style={{ width: 200, height: 100 }}
        payButtonProps={{
          marginLeft: 20,
          marginTop: 20,
          backgroundColor: '#026cff',
          text: 'Pay',
          textSize: 20,
          textColor: '#ffffff',
          buttonWidth: 40,
          buttonHeight: 40,
          borderRadius: 20,
          borderWidth: 1,
          borderColor: '#383333',
        }}
        onFailure={onFailure}
        onSuccess={onSuccess}
      />
    )

Custom UI and Direct Checkout Props

NameValueDescriptionMandatory
environment'TEST', 'PRODUCTION'Parameter used to determine whether the request is going to be submitted to the test or production environment.Yes
styleobjectSet the height and width of the viewYes
payButtonPropsobjectCustomization of the pay buttonYes
requestObjectobjectParameters you need to send when you send a request (the full list of parameters is in the last section of the document)Yes
onSuccessfunctionCallback to handle when the transaction is processed successfully.Yes
onFailurefunctionCallback to handle when the transaction is failed.Yes

Request Parameters (FortRequestObject)

AttributeTypeDescriptionMandatoryMaximumExample
commandAlphaCommand.Possible/ expected values: AUTHORIZATION, PURCHASEYes20PURCHASE
merchant_referenceAlphanumericThe Merchant’s unique order number.Yes40XYZ9239-yu898
amountNumericThe transaction’s amount. *Each currency has predefined allowed decimal points that should be taken into consideration when sending the amountYes1010000
currencyAlphaThe currency of the transaction’s amount in ISO code 3.Yes3AED
languageAlphaThe checkout page and messages language.Possible/ expected values: en/ arYes2en
customer_emailAlphanumericThe customer’s email.Special characters: _ - . @ +Yes254customer@domain.com
sdk_tokenAlphanumericAn SDK Token to enable using the Amazon Payment Services Mobile SDK.Yes100Dwp78q3
token_nameAlphanumericThe Token received from the Tokenization process.Special characters: . @ - _No100Op9Vmp
payment_optionAlphaPayment option.Possible/ expected values:- MASTERCARD- VISA- AMEX- MADA (for Purchase operations and eci Ecommerce only) Click here to download MADA Branding Document - MEEZA (for Purchase operations and ECOMMERCE eci only)No10VISA
eciAlphaEcommerce indicator.Possible/ expected values: ECOMMERCENo150ECOMMERCE
order_descriptionAlphanumericA description of the order.Special characters:'/ . _ - # : $ SpaceNo150iPhone 6-S
customer_ipAlphanumericIt holds the customer’s IP address. It’s Mandatory, if the fraud service is active. We support IPv4 and IPv6 as shown in the example below.No45IPv4 → 192.178.1.10IPv6 → 2001:0db8:3042:0002:5a55:caff:fef6:bdbf
customer_nameAlphaThe customer’s name.Special characters: _ \ / - .'No40John Smith
phone_numberAlphanumericThe customer’s phone number.Special characters: + - ( ) SpaceNo1900962797219966
settlement_referenceAlphanumericThe Merchant submits unique value to Amazon Payment Services. The value is then passed to the Acquiring bank and displayed to the merchant in the Acquirer settlement file.No34XYZ9239-yu898
merchant_extra1AlphanumericExtra data sent by merchant. Will be received and sent back as received. Will not be displayed in any report.No250JohnSmith
merchant_extra2AlphanumericExtra data sent by merchant. Will be received and sent back as received. Will not be displayed in any report.No250JohnSmith
merchant_extra3AlphanumericExtra data sent by merchant. Will be received and sent back as received. Will not be displayed in any report.No250JohnSmith
merchant_extra4AlphanumericExtra data sent by merchant. Will be received and sent back as received. Will not be displayed in any report.No250JohnSmith
merchant_extra5AlphanumericExtra data sent by merchant. Will be received and sent back as received. Will not be displayed in any report.No250JohnSmith

License

MIT

0.2.3

11 months ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago