-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dc68c3
commit 35af7b4
Showing
4 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PayPalStrategy } from './index'; | ||
|
||
// const debug = require('debug')('recurly:paypal:strategy:complete'); | ||
|
||
const PAYPAL_COMPLETE_START_PATH = '/paypal_commerce/start'; | ||
|
||
/** | ||
* PayPal Complete strategy | ||
*/ | ||
export class CompleteStrategy extends PayPalStrategy { | ||
constructor (...args) { | ||
super(...args); | ||
this.emit('ready'); | ||
} | ||
|
||
start () { | ||
const frame = this.frame = this.recurly.Frame({ path: PAYPAL_COMPLETE_START_PATH }); | ||
frame.once('done', token => this.emit('token', token)); | ||
frame.once('close', () => this.emit('cancel')); | ||
frame.once('error', cause => { | ||
if (cause.code === 'paypal-cancel') this.emit('cancel'); | ||
this.error('paypal-tokenize-error', { cause }); | ||
}); | ||
} | ||
|
||
destroy () { | ||
if (this.frame) { | ||
this.frame.destroy(); | ||
} | ||
this.off(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import assert from 'assert'; | ||
|
||
import { | ||
initRecurly, | ||
stubWindowOpen | ||
} from '../../support/helpers'; | ||
|
||
describe('CompleteStrategy', function () { | ||
const validOpts = { payPalComplete: true }; | ||
|
||
stubWindowOpen(); | ||
|
||
beforeEach(function () { | ||
this.sandbox = sinon.createSandbox(); | ||
this.recurly = initRecurly(); | ||
this.paypal = this.recurly.PayPal(validOpts); | ||
}); | ||
|
||
describe('start', function () { | ||
it('opens iframe with PayPal Complete start path', function () { | ||
this.sandbox.spy(this.recurly, 'Frame'); | ||
this.paypal.start(); | ||
console.log({ calls: this.recurly.Frame.getCalls() }); | ||
assert(this.recurly.Frame.calledWith({ path: '/paypal_commerce/start' })); | ||
}); | ||
}); | ||
}); |