Package: pgrwpy
PG Rewards SDK - PythonThe PG Rewards API SDK Python helps you create your virtual or physical and start spending onlineHave a question or need some help?:Website|Email|HelpSo you are a developer and will start accepting payments with moncash. The PG Rewards Payments SDK is the easiest way to complete the integration in record time. With the PG Rewards Payment SDK, you can create a payment process through moncash to meet the unique needs of your projects.Table of ContentsPython Django ExampleGetting an API KeyPayment with MoncashPayment DetailSend RewardsCreate CardCard DetailList CardsPython Django Example$cdexample
$virtualenvenv
$sourceenv/bin/activate
$pipinstall-rrequirements.txt
$pythonmanage.pyrunserverGetting an API Keybefore we start the integration make sure you have:Registeredfor a PG Rewards developer AccountNavigate to Settings > Developer SettingClick on Generate New Credentials to get new credentialsInstall pip package$pipinstallpgrwpyGetting StartedYou need to setup your key and secret using the following:To work in production mode you need to specify your production PG_USER_ID & PG_SECRET_KEY along with a production_mode True boolean flagimportpgrwpyclient=pgrwpy.Client(auth=(PG_USER_ID,PG_SECRET_KEY),production_mode=True)orTo work in sandbox mode you need to specify your sandbox PG_USER_ID & PG_SECRET_KEY keys along with a False boolean flag or you could just omit the production_mode flag since it defaults to False if not specifiedimportpgrwpyclient=pgrwpy.Client(auth=(PG_USER_ID,PG_SECRET_KEY),production_mode=False)After setting up the client instance you can get the current pgrwpy SDK version using the following:print(client.get_version())Create a paymet with Mon CashIn order to receive payments using this flow, first of all you will need to create a Moncash payment. Following are the important parameters that you can provide for this method:FieldRequiredTypeDescriptionamountYesnumberAmount in Haitian Currency (gourdes)referenceIdYesstringYour internal reference ID into your own system for tracking purposessuccessUrlYesstringSend the user back once the transaction is successfully completeerrorUrlYesstringSend the user back if there is an error with the transactionFor details of all the request and response parameters , check ourPG API Documentation guidedata={"amount":500,"referenceId":"12345test","successUrl":"https://example.com","errorUrl":"https://example.com"}payment=client.Payment.moncash(data)print(payment['redirectUrl'])#the redirect moncash linkDid you get aHTTP 201response, if yes then you are all set for the next step.Get Payment DetailsNow that you have created a payment, the next step is to implement polling to get Payment Details. We recommend a 4-5 second interval between requests. Following are the important parameters that you can provide for this method:FieldRequiredTypeDescriptionorderIdYesstringYour internal reference ID into your own system for tracking purposesFetch a particular Moncash payment detailsres=client.Payment.get_payment_details("<orderId>")print(res)# 200: OKFor details of all the request and response parameters , check ourPG API Documentation guideOn successful payment, the status in the response will change toCOMPLETEDIn case of a pending for Payment, the status in the response will change toPENDINGRewards SchemaYou can use send rewards as a way to recharge a user's account. The funds will automatically be available on their virtual or physical card. Following are the important parameters that you can provide for this method:FieldRequiredTypeDescriptionemailYesstringRecipient emailamountYesnumberAmount for the recipientprepaidYesbooleanUser created via your platform, default trueSend rewardsdata={"email":"info@pgecom.com","amount":10,"prepaid":False,}res=client.Reward.send(data)print(res)# 200: OKFor details of all the request and response parameters , check ourPG API Documentation guideDid you get aHTTP 201response, if yes then you are all set for the next step.Card SchemaIn order to create a card, you will need to send a request to us with the following parameters:FieldRequiredTypeDescriptionfullNameYesnumberRecipient that needs to be on the cardamountYesstringAvailable mount to spend with the cardemailYesstringEmail of the card recipientbillingAddressYesobjectRecipient address on the card. The country is required inside billingAddressphysicalYesbooleanIf set to true, then card shipped to the provided address - only shipping for physical USApersonYesstringprepaid/user - user is a registered user on the platform, and prepaid is just temporary prepaid card with a limited amount and limited featureThe billing address object reference aboveFieldRequiredTypeDescriptionline1Yesstringrecipient street addresscityYesstringrecipient citycountryYesstringrecipient countrystateYesstringrecipient statepostal_codeYesnumberrecipient postal codeFor details of all the request and response parameters , check ourPG API Documentation guidedata={"fullName":"Stanley Castin","amount":5,"email":"stanley@ninja.root","billingAddress":{"line1":"9700 Medlock Bridge Road","city":"John Creeks","country":"US","state":"WA","postal_code":"90098"},"physical":False,"person":"prepaid"# prepaid | user}res=client.Card.create(data)print(res)# 200: OKDid you get aHTTP 201response, if yes then you are all set for the next step.Retrieve a single cardNow that you have created a card, the next step is to implement polling to get Card Details. We recommend a 4-5 second interval between requests. Following are the important parameters that you can provide for this method:FieldRequiredTypeDescriptioncardIdYesstringthe actual card idcardHolderIdYesstringThe owner of the cardFetch a particular Card detailsres=client.Card.get_card_details("<cardId>","<cardHolderId>")print(res)# 200: OKFor details of all the request and response parameters , check ourPG API Documentation guideList cardsthe next step is to implement polling to get all Cards. We recommend a 4-5 second interval between requests. Following are the important parameters that you can provide for this method:FieldRequiredTypeDescriptioncardHolderIdYesstringThe owner of the cardFetch all Cardsres=client.Card.get_all_cards("<cardHolderId>")print(res)# 200: OKFor details of all the request and response parameters , check ourPG API Documentation guideTask | workflowPayment with MoncashPayment DetailSend RewardsCreate CardCard DetailList Cards