Commit afce584f by Nilu

stripe data pull batch. Mapping plans from stripe to app.

parent 288caf8d
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_payment_plan</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="stripe_reference" type="String" nullable="false" length="100"/>
<column name="plan_name" type="CLOB" nullable="true"/>
<column name="description" type="CLOB" nullable="true"/>
<column name="currency_type" type="String" nullable="false" length="200"/>
<column name="amount" type="Double" nullable="false"/>
<column name="interval" type="String" nullable="false" length="200"/>
<column name="interval_count" type="Long" nullable="false"/>
<column name="trial_period_days" type="Long" nullable="true"/>
<column name="active_job_count" type="Long" nullable="true"/>
</NODE>
</NODE></OBJECTS>
\ No newline at end of file
-- DROP TABLE tl_payment_plan;
CREATE TABLE tl_payment_plan (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
stripe_reference varchar(100) NOT NULL,
plan_name text NULL,
description text NULL,
currency_type varchar(200) NOT NULL,
amount numeric(20,5) NOT NULL,
interval varchar(200) NOT NULL,
interval_count numeric(12) NOT NULL,
trial_period_days numeric(12) NULL,
active_job_count numeric(12) NULL
);
ALTER TABLE tl_payment_plan ADD
CONSTRAINT PK_tl_payment_plan PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- DROP TABLE tl_payment_plan;
CREATE TABLE tl_payment_plan (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
stripe_reference varchar2(100) NOT NULL,
plan_name clob NULL,
description clob NULL,
currency_type varchar2(200) NOT NULL,
amount number(20,5) NOT NULL,
interval varchar2(200) NOT NULL,
interval_count number(12) NOT NULL,
trial_period_days number(12) NULL,
active_job_count number(12) NULL
);
ALTER TABLE tl_payment_plan ADD
CONSTRAINT PK_tl_payment_plan PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- @AutoRun
-- drop table tl_payment_plan;
CREATE TABLE tl_payment_plan (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
stripe_reference varchar(100) NOT NULL,
plan_name text NULL,
description text NULL,
currency_type varchar(200) NOT NULL,
amount numeric(20,5) NOT NULL,
interval varchar(200) NOT NULL,
interval_count numeric(12) NOT NULL,
trial_period_days numeric(12) NULL,
active_job_count numeric(12) NULL
);
ALTER TABLE tl_payment_plan ADD
CONSTRAINT pk_tl_payment_plan PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
package performa.batch;
import com.stripe.Stripe;
import com.stripe.model.Plan;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import oneit.appservices.batch.ORMBatch;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.utils.parsers.FieldException;
import performa.orm.PaymentPlan;
import performa.orm.types.CurrencyType;
import performa.orm.types.Interval;
import performa.utils.StripeUtils;
public class PullStripeDataBatch extends ORMBatch
{
public static LoggingArea PULL_STRIPE_DATA_BATCH = LoggingArea.createLoggingArea("PullStripeDataBatch");
@Override
public void run(ObjectTransaction ot) throws StorageException, FieldException
{
try
{
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.DEBUG2, "RUNNING Pull Stripe Data Batch");
Stripe.apiKey = StripeUtils.STRIPE_KEY;
Map<String, Object> planParams = new HashMap<>();
List<Plan> plansList = Plan.list(planParams).getData();
for (Plan plan : plansList)
{
PaymentPlan[] paymentPlans = PaymentPlan.SearchByAll().andStripeReference(new EqualsFilter<>(plan.getId())).search(ot);
PaymentPlan paymentPlan;
if(paymentPlans != null && paymentPlans.length > 0)
{
paymentPlan = paymentPlans[0];
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.DEBUG2, "Updating exiting payment plan: " , paymentPlan, " to match stripe plan: ", plan);
}
else
{
paymentPlan = PaymentPlan.createPaymentPlan(ot);
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.DEBUG2, "Creating a new payment plan for stripe plan: ", plan);
}
Map<String, String> metadata = plan.getMetadata();
String activeJobs = metadata.get("ActiveJobs");
paymentPlan.setStripeReference(plan.getId());
paymentPlan.setPlanName(plan.getName());
paymentPlan.setDescription(plan.getStatementDescriptor());
paymentPlan.setCurrencyType(CurrencyType.forName(plan.getCurrency().toUpperCase()));
paymentPlan.setAmount(plan.getAmount().doubleValue() / 100);
paymentPlan.setInterval(Interval.forName(plan.getInterval().toUpperCase()));
paymentPlan.setIntervalCount(plan.getIntervalCount());
paymentPlan.setTrialPeriodDays(plan.getTrialPeriodDays());
if(activeJobs != null)
{
paymentPlan.setActiveJobCount(Integer.valueOf(activeJobs));
}
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.DEBUG2, "Saving payment plan: " , paymentPlan, " mapped from stripe plan: ", plan);
}
}
catch (Exception ex)
{
LogMgr.log(PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, ex, "Error while pulling plan details from stripe");
}
}
}
\ No newline at end of file
package performa.form;
import com.stripe.Stripe;
import com.stripe.model.Plan;
import com.stripe.model.PlanCollection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import oneit.appservices.config.ConfigMgr;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import performa.orm.Job;
import performa.orm.PaymentPlan;
import performa.orm.types.CurrencyType;
import performa.orm.types.Interval;
public class ManagePlansFP extends SaveFP
{
public static final String STRIPE_KEY = ConfigMgr.getKeyfileString("stripe.key","");
public static final String STRIPE_PUB_KEY = ConfigMgr.getKeyfileString("stripe.pubkey","");
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException
{
HttpServletRequest request = submission.getRequest();
LogMgr.log(Job.LOG, LogLevel.PROCESSING1,"In ManagePlansFP : " );
Stripe.apiKey = STRIPE_KEY;
try {
Map<String, Object> planParams = new HashMap<>();
PlanCollection list = Plan.list(planParams);
List<Plan> lists = list.getData();
for (Plan plan : lists)
{
// Map<String, String> metadata = plan.getMetadata();
// PaymentPlan paymentPlan = PaymentPlan.createPaymentPlan(process.getTransaction());
//
// paymentPlan.setStripeReference(plan.getId());
// paymentPlan.setPlanName(plan.getName());
// paymentPlan.setDescription(plan.getStatementDescriptor());
// paymentPlan.setCurrencyType(CurrencyType.forName(plan.getCurrency().toUpperCase()));
// paymentPlan.setAmount(plan.getAmount().doubleValue());
// paymentPlan.setInterval(Interval.forName(plan.getInterval().toUpperCase()));
// paymentPlan.setIntervalCount(plan.getIntervalCount());
// paymentPlan.setTrialPeriodDays(plan.getTrialPeriodDays());
// paymentPlan.setActiveJobCount(Integer.valueOf(metadata.get("ActiveJobs")));
}
} catch (Exception ex)
{
Logger.getLogger(ManagePlansFP.class.getName()).log(Level.SEVERE, null, ex);
}
return super.processForm(process, submission, p);
}
}
package performa.orm;
import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.utils.*;
import performa.orm.types.*;
public class PaymentPlan extends BasePaymentPlan
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public PaymentPlan ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="PaymentPlan" package="performa.orm">
<IMPORT value="performa.orm.types.*"/>
<TABLE name="tl_payment_plan" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="StripeReference" type="String" dbcol="stripe_reference" length="100" mandatory="true"/>
<ATTRIB name="PlanName" type="String" dbcol="plan_name" />
<ATTRIB name="Description" type="String" dbcol="description" />
<ATTRIB name="CurrencyType" type="CurrencyType" dbcol="currency_type" mandatory="true" attribHelper="EnumeratedAttributeHelper" defaultValue="CurrencyType.AUD"/>
<ATTRIB name="Amount" type="Double" dbcol="amount" mandatory="true" SubType="Currency" Formatter="Currency" />
<ATTRIB name="Interval" type="Interval" dbcol="interval" mandatory="true" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="IntervalCount" type="Integer" dbcol="interval_count" mandatory="true"/>
<ATTRIB name="TrialPeriodDays" type="Integer" dbcol="trial_period_days" />
<ATTRIB name="ActiveJobCount" type="Integer" dbcol="active_job_count" />
</TABLE>
<SEARCH type="All" paramFilter="tl_payment_plan.object_id is not null" orderBy="tl_payment_plan.object_id" />
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
package performa.orm.types;
import java.util.*;
import oneit.utils.*;
/**
* This class was generated using constGen.bat.
* DO NOT MODIFY THIS CODE.
* Edit the associated .xml file, and regenerate this file
* constGen (directory) (file minus extension)
* e.g. constGen C:\...\sql FieldType
*/
public class CurrencyType extends AbstractEnumerated
{
public static final EnumeratedFactory FACTORY_CurrencyType = new CurrencyTypeFactory();
public static final CurrencyType AUD = new CurrencyType ("AUD", "AUD", "AUD", false);
public static final CurrencyType NZD = new CurrencyType ("NZD", "NZD", "NZD", false);
public static final CurrencyType EUR = new CurrencyType ("EUR", "EUR", "EUR", false);
public static final CurrencyType GBP = new CurrencyType ("GBP", "GBP", "GBP", false);
public static final CurrencyType USD = new CurrencyType ("USD", "USD", "USD", false);
public static final CurrencyType SGD = new CurrencyType ("SGD", "SGD", "SGD", false);
private static final CurrencyType[] allCurrencyTypes =
new CurrencyType[] { AUD,NZD,EUR,GBP,USD,SGD};
private static CurrencyType[] getAllCurrencyTypes ()
{
return allCurrencyTypes;
}
private CurrencyType (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allCurrencyTypes);
static
{
defineAdditionalData ();
}
public boolean isEqual (CurrencyType other)
{
return this.name.equals (other.name);
}
public Enumeration getAllInstances ()
{
return CurrencyType.getAll ();
}
private Object readResolve() throws java.io.ObjectStreamException
{
return CurrencyType.forName (this.name);
}
public EnumeratedFactory getFactory ()
{
return FACTORY_CurrencyType;
}
public static CurrencyType forName (String name)
{
if (name == null) { return null; }
CurrencyType[] all = getAllCurrencyTypes();
int enumIndex = AbstractEnumerated.getIndexForName (all, name);
return all[enumIndex];
}
public static CurrencyType forValue (String value)
{
if (value == null) { return null; }
CurrencyType[] all = getAllCurrencyTypes();
int enumIndex = AbstractEnumerated.getIndexForValue (getAllCurrencyTypes (), value);
return all[enumIndex];
}
public static java.util.Enumeration getAll ()
{
return AbstractEnumerated.getAll (getAllCurrencyTypes());
}
public static CurrencyType[] getCurrencyTypeArray ()
{
return (CurrencyType[])getAllCurrencyTypes().clone ();
}
public static void defineAdditionalData ()
{
}
static class CurrencyTypeFactory implements EnumeratedFactory
{
public AbstractEnumerated getForName (String name)
{
return CurrencyType.forName (name);
}
public AbstractEnumerated getForValue (String name)
{
return CurrencyType.forValue (name);
}
public Enumeration getAll ()
{
return CurrencyType.getAll ();
}
}
public Map getAdditionalAttributes ()
{
Map attribs = new HashMap ();
return attribs;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CONSTANT package="performa.orm.types" name="CurrencyType">
<VALUE name="AUD" description="AUD" />
<VALUE name="NZD" description="NZD" />
<VALUE name="EUR" description="EUR" />
<VALUE name="GBP" description="GBP" />
<VALUE name="USD" description="USD" />
<VALUE name="SGD" description="SGD" />
</CONSTANT>
</ROOT>
package performa.orm.types;
import java.util.*;
import oneit.utils.*;
/**
* This class was generated using constGen.bat.
* DO NOT MODIFY THIS CODE.
* Edit the associated .xml file, and regenerate this file
* constGen (directory) (file minus extension)
* e.g. constGen C:\...\sql FieldType
*/
public class Interval extends AbstractEnumerated
{
public static final EnumeratedFactory FACTORY_Interval = new IntervalFactory();
public static final Interval DAY = new Interval ("DAY", "DAY", "Day", false);
public static final Interval WEEK = new Interval ("WEEK", "WEEK", "Week", false);
public static final Interval MONTH = new Interval ("MONTH", "MONTH", "Month", false);
public static final Interval YEAR = new Interval ("YEAR", "YEAR", "Year", false);
private static final Interval[] allIntervals =
new Interval[] { DAY,WEEK,MONTH,YEAR};
private static Interval[] getAllIntervals ()
{
return allIntervals;
}
private Interval (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allIntervals);
static
{
defineAdditionalData ();
}
public boolean isEqual (Interval other)
{
return this.name.equals (other.name);
}
public Enumeration getAllInstances ()
{
return Interval.getAll ();
}
private Object readResolve() throws java.io.ObjectStreamException
{
return Interval.forName (this.name);
}
public EnumeratedFactory getFactory ()
{
return FACTORY_Interval;
}
public static Interval forName (String name)
{
if (name == null) { return null; }
Interval[] all = getAllIntervals();
int enumIndex = AbstractEnumerated.getIndexForName (all, name);
return all[enumIndex];
}
public static Interval forValue (String value)
{
if (value == null) { return null; }
Interval[] all = getAllIntervals();
int enumIndex = AbstractEnumerated.getIndexForValue (getAllIntervals (), value);
return all[enumIndex];
}
public static java.util.Enumeration getAll ()
{
return AbstractEnumerated.getAll (getAllIntervals());
}
public static Interval[] getIntervalArray ()
{
return (Interval[])getAllIntervals().clone ();
}
public static void defineAdditionalData ()
{
}
static class IntervalFactory implements EnumeratedFactory
{
public AbstractEnumerated getForName (String name)
{
return Interval.forName (name);
}
public AbstractEnumerated getForValue (String name)
{
return Interval.forValue (name);
}
public Enumeration getAll ()
{
return Interval.getAll ();
}
}
public Map getAdditionalAttributes ()
{
Map attribs = new HashMap ();
return attribs;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CONSTANT package="performa.orm.types" name="Interval">
<VALUE name="DAY" description="Day" />
<VALUE name="WEEK" description="Week" />
<VALUE name="MONTH" description="Month" />
<VALUE name="YEAR" description="Year" />
</CONSTANT>
</ROOT>
\ No newline at end of file
...@@ -61,6 +61,31 @@ public class StripeUtils ...@@ -61,6 +61,31 @@ public class StripeUtils
} }
public static void updateCardDetails(Company company, String token) throws FieldException
{
try
{
if(company.getStripeReference() == null)
{
createCustomer(company.getAddedByUser());
}
Customer customer = Customer.retrieve(company.getStripeReference());
Map<String, Object> updateParams = new HashMap<>();
updateParams.put("source", token);
customer.update(updateParams);
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while updating a customer in stripe");
}
}
public static void subscribeCustomer(Company company) throws FieldException public static void subscribeCustomer(Company company) throws FieldException
{ {
try try
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/> <FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/>
<FORM name="*.processCulture" factory="Participant" class="performa.form.ProcessCultureFP"/> <FORM name="*.processCulture" factory="Participant" class="performa.form.ProcessCultureFP"/>
<FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/> <FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/>
<FORM name="*.managePlans" factory="Participant" class="performa.form.ManagePlansFP"/>
</NODE> </NODE>
<NODE name="job_assessment_criteria_add_jsp" factory="Participant"> <NODE name="job_assessment_criteria_add_jsp" factory="Participant">
......
...@@ -133,6 +133,18 @@ ...@@ -133,6 +133,18 @@
</TASK> </TASK>
<TASK factory="Participant" class="oneit.appservices.batch.DefaultTask" lockName="performa"> <TASK factory="Participant" class="oneit.appservices.batch.DefaultTask" lockName="performa">
<RUN class="performa.batch.PullStripeDataBatch" factory="Participant"/>
<WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.runbatch">
<NODE name="schedule" class="oneit.appservices.batch.HourlySchedule">
<NODE name="minuteOfHour" factory="Integer" value="1"/>
</NODE>
</WHEN>
</TASK>
<TASK factory="Participant" class="oneit.appservices.batch.DefaultTask" lockName="performa">
<RUN class="performa.batch.URLShortnerBatch" factory="Participant"/> <RUN class="performa.batch.URLShortnerBatch" factory="Participant"/>
<WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.runbatch"> <WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.runbatch">
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
Debug.assertion(company != null , "Invalid company in admin portal my company"); Debug.assertion(company != null , "Invalid company in admin portal my company");
String nextPage = WebUtils.getSamePageInRenderMode(request, "Page"); String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing");
%> %>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() $(document).ready(function()
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="company-detail"> <div class="tab-pane active" id="company-detail">
<div class="tabpage-title"> <div class="tabpage-title">
<label class="label-20">Billing</label> <label class="label-20">Billing</label><br/>
<span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span>
</div> </div>
<div> <div>
<label class="label-14 bold">Add a payment method</label><br/> <label class="label-14 bold">Add a payment method</label><br/>
...@@ -71,7 +72,6 @@ ...@@ -71,7 +72,6 @@
<oneit:ormInput obj="<%= company %>" type="text" attributeName="PostCode" cssClass="form-control" /> <oneit:ormInput obj="<%= company %>" type="text" attributeName="PostCode" cssClass="form-control" />
</div> </div>
</div> </div>
<div id="card-errors" role="alert"></div>
<div class="form-group"> <div class="form-group">
<oneit:button value="Save Card" name="saveCompany" cssClass="btn btn-primary btn-green large-btn" <oneit:button value="Save Card" name="saveCompany" cssClass="btn btn-primary btn-green large-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage) requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</div> </div>
<div> <div>
<label class="label-20">Pay Per Plan</label> <label class="label-20">Pay Per Job</label>
</div> </div>
<div class="grey-area"> <div class="grey-area">
<div class="text-center"> <div class="text-center">
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<label class="label-14">Per Job</label> <label class="label-14">Per Job</label>
</div> </div>
<div class="text-center form-group"> <div class="text-center form-group">
<oneit:button value="Upgrade" name="saveCompany" cssClass="btn btn-primary btn-green large-btn" <oneit:button value="Upgrade" name="managePlans" cssClass="btn btn-primary btn-green large-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage) requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company) .mapEntry("Company", company)
.toMap() %>" /> .toMap() %>" />
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_payment_plan</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="stripe_reference" type="String" nullable="false" length="100"/>
<column name="plan_name" type="CLOB" nullable="true"/>
<column name="description" type="CLOB" nullable="true"/>
<column name="currency_type" type="String" nullable="false" length="200"/>
<column name="amount" type="Double" nullable="false"/>
<column name="interval" type="String" nullable="false" length="200"/>
<column name="interval_count" type="Long" nullable="false"/>
<column name="trial_period_days" type="Long" nullable="true"/>
<column name="active_job_count" type="Long" nullable="true"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
...@@ -67,21 +67,22 @@ cardCvc.addEventListener('change', function(event) { ...@@ -67,21 +67,22 @@ cardCvc.addEventListener('change', function(event) {
// Create a token or display an error when the form is submitted. // Create a token or display an error when the form is submitted.
var form = document.getElementById('makePayment'); var form = document.getElementById('makePayment');
form.addEventListener('submit', function(event) { form.addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
stripe.createToken(cardNumber).then(function(result) { stripe.createToken(cardNumber, {name: "Demo Card Name"}).then(function(result) {
if (result.error) { if (result.error) {
// Inform the customer that there was an error // Inform the customer that there was an error
var errorElement = document.getElementById('card-errors'); var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message; errorElement.textContent = result.error.message;
} else { } else {
// Send the token to your server // Send the token to your server
$('input[name=stripe-token-id]').val(result.token.id); $('input[name=stripe-token-id]').val(result.token.id);
$('#payNow').click(); $('#payNow').click();
// stripeTokenHandler(result.token); // stripeTokenHandler(result.token);
} }
}); });
}); });
function stripeTokenHandler(token) { function stripeTokenHandler(token) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment